문제출처 : https://www.acmicpc.net/problem/14222
code
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
int i, N, K;
bool ispossible = true;
cin >> N >> K;
vector<int> arr(N);
for (i = 0; i < N; i++)
cin >> arr[i];
sort(arr.begin(), arr.end());
for (i = 0; i < N; i++)
{
if (arr[i] == i + 1)
{
continue;
}
else if (arr[i] > i + 1)
{
ispossible = false;
}
else
{
arr[i] += K;
i--;
}
sort(arr.begin(), arr.end());
}
if (ispossible)
cout << 1;
else
cout << 0;
return 0;
}