This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int64_t n, k, a[100000+1], temp = 0;
vector<int64_t> ans;
bool possible = true;
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> k;
for(int64_t i=0; i<n; i++) {
cin >> a[i];
}
sort(a,a+n);
for(int64_t i=n-k; i<n; i++) {
ans.push_back(a[i]);
}
for(int64_t i=0; i<n-k; i++) {
ans.push_back(a[i]);
}
for(int64_t i=0; i<n; i++) {
if(i < k) {
if(ans[i] <= temp) {
possible = false;
break;
}
temp++;
}
else if(ans[i] > k) {
possible = false;
break;
}
}
if(!possible) cout << "-1\n";
else {
reverse(ans.begin(), ans.end());
for(auto i : ans) {
cout << i << " ";
}
cout << '\n';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |