//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << " " <<
#define nl << "\n"
signed main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
int n, k; cin >> n >> k;
int a[n];
for(int &i : a) cin >> i;
sort(a, a+n);
vector<int> ans;
for(int i=n-k; i<n; ++i) ans.push_back(a[i]);
for(int i=0; i<n-k; ++i) ans.push_back(a[i]);
bool ok = true;
int prev = 0;
for(int i=0; i<n; ++i){
if(i<k){
if(ans[i]<=prev) ok = false;
++prev;
}else{
if(ans[i]>k) ok = false;
}
}
reverse(ans.begin(), ans.end());
if(ok){
for(int i : ans) cout << i << ' ';
}else cout << -1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
3176 KB |
Output is correct |
2 |
Correct |
18 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
5860 KB |
Output is correct |
2 |
Correct |
41 ms |
5224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
130 ms |
13792 KB |
Output is correct |
2 |
Correct |
84 ms |
11480 KB |
Output is correct |