# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
237545 |
2020-06-07T08:38:06 Z |
VEGAnn |
Karte (COCI18_karte) |
C++14 |
|
138 ms |
6776 KB |
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 500100;
int n, k, a[N], b[N];
int get(int kl){
for (int i = n - kl, j = 0; i < n; i++, j++)
b[j] = a[i];
for (int i = 0, j = kl; i < n - kl; i++, j++)
b[j] = a[i];
int cnt = 0;
bool ok = 1;
for (int i = 0; i < n; i++)
if (b[i] > cnt)
cnt++;
return cnt;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> a[i];
sort(a, a + n);
int l = 0, r = n;
while (l < r){
int md = (l + r) >> 1;
if (get(md) >= k)
r = md;
else l = md + 1;
}
int kl = l;
for (int i = n - kl, j = 0; i < n; i++, j++)
b[j] = a[i];
for (int i = 0, j = kl; i < n - kl; i++, j++)
b[j] = a[i];
int cnt = 0;
bool ok = 1;
for (int i = 0; i < n && ok; i++)
if (b[i] > cnt)
cnt++;
if (cnt == k && ok) {
for (int i = n - 1; i >= 0; i--)
cout << b[i] << " ";
return 0;
}
cout << -1;
return 0;
}
Compilation message
karte.cpp: In function 'int get(int)':
karte.cpp:17:10: warning: unused variable 'ok' [-Wunused-variable]
bool ok = 1;
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1664 KB |
Output is correct |
2 |
Correct |
26 ms |
1152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
44 ms |
1920 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
6776 KB |
Output is correct |
2 |
Correct |
102 ms |
4216 KB |
Output is correct |