# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
237542 |
2020-06-07T08:32:27 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 < kl && ok; 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 = k, 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) {
if (i >= kl)
ok = 0;
else cnt++;
}
}
if (cnt == k && ok) {
for (int i = n - 1; i >= 0; i--)
cout << b[i] << " ";
return 0;
}
cout << -1;
return 0;
}
# |
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 |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
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 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
1656 KB |
Output is correct |
2 |
Correct |
22 ms |
1144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
2936 KB |
Output is correct |
2 |
Correct |
42 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
6776 KB |
Output is correct |
2 |
Correct |
94 ms |
4216 KB |
Output is correct |