#include<bits/stdc++.h>
#define endl '\n'
#pragma GCC optimize("Ofast")
using namespace std;
const int MAXN = 5e5 + 10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int n, k, a[MAXN];
void read()
{
cin >> n >> k;
int cnt0 = 0;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
if(!a[i])cnt0 ++;
}
sort(a+1, a+n+1);
if(k == 0)
{
if(cnt0 != n)cout << -1 << endl;
else
{
for (int i = 1; i <= n; ++ i)
cout << a[i] << " ";
cout << endl;
}
exit(0);
}
int cnt_false = 0;
vector < int > g;
for(int i = n - k + 1; i <= n; ++ i)
{
g.push_back(a[i]);
if(a[i] > cnt_false)cnt_false ++;
}
for (int i = 1; i <= n - k; ++ i)
{
g.push_back(a[i]);
if(a[i] > cnt_false)
{
cnt_false ++;
return;
}
}
//cout << cnt_false << endl;
if(cnt_false == k)
{
for (int i = g.size()-1; i >= 0; -- i)
cout << g[i] << " ";
cout << endl;
}
else cout << -1 << endl;
}
int main()
{
speed();
read();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Failed |
0 ms |
348 KB |
Checker failed - contact admins or jury |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Failed |
0 ms |
348 KB |
Checker failed - contact admins or jury |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Failed |
0 ms |
348 KB |
Checker failed - contact admins or jury |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
1756 KB |
Output is correct |
2 |
Failed |
13 ms |
1112 KB |
Checker failed - contact admins or jury |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
34 ms |
3032 KB |
Output is correct |
2 |
Failed |
29 ms |
2388 KB |
Checker failed - contact admins or jury |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
80 ms |
6856 KB |
Output is correct |
2 |
Failed |
55 ms |
4572 KB |
Checker failed - contact admins or jury |
3 |
Halted |
0 ms |
0 KB |
- |