Files
python/TangDou/CSP-J/AcWingTraining/Iamthebest.cpp

42 lines
1.1 KiB
C++
Raw Normal View History

2025-08-30 18:35:01 +08:00
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int a[N];
int st[N];
int n, w;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
cin >> w;
if (n % w) {
cout << "false" << endl;
return 0;
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
if (!st[i]) {
st[i] = 1;
int start = i + 1;
int target = a[i] + 1;
for (int j = 1; j < w; j++) {
bool flag = false;
for (int k = start; k <= n; k++) {
if (!st[k] && a[k] == target) {
st[k] = 1;
flag = true;
start = k + 1;
target++;
break;
}
}
if (!flag) {
cout << "false" << endl;
return 0;
}
}
}
}
cout << "true" << endl;
return 0;
}