# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
767723 |
2023-06-27T05:48:42 Z |
Trunkty |
Gift (IZhO18_nicegift) |
C++14 |
|
2000 ms |
233512 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
int n,k,tot;
int arr[1000005];
map<int,vector<int>> vals;
multiset<int> s;
vector<vector<int>> ans;
signed main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> k;
for(int i=1;i<=n;i++){
cin >> arr[i];
s.insert(arr[i]);
vals[arr[i]].push_back(i);
tot += arr[i];
}
if(tot%k!=0 or tot/k<(*prev(s.end()))){
cout << -1 << "\n";
return 0;
}
int lef=tot/k;
s.insert(0);
while((*prev(s.end()))>0){
vector<int> v;
auto it = s.end();
for(int i=1;i<=k;i++){
it--;
v.push_back((*it));
}
for(int i:v){
s.erase(s.find(i));
}
int torem = min(v.back(),lef-(*prev(s.end())));
lef -= torem;
vector<int> ps={torem};
reverse(v.begin(),v.end());
for(int i:v){
int x = vals[i].back();
vals[i].pop_back();
ps.push_back(x);
vals[i-torem].push_back(x);
s.insert(i-torem);
}
ans.push_back(ps);
}
cout << ans.size() << "\n";
for(vector<int> i:ans){
for(int j:i){
cout << j << " ";
}
cout << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
328 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
212 KB |
n=4 |
6 |
Correct |
1 ms |
376 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
328 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
212 KB |
n=4 |
6 |
Correct |
1 ms |
376 KB |
n=2 |
7 |
Correct |
1 ms |
328 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
328 KB |
n=14 |
10 |
Correct |
1 ms |
212 KB |
n=11 |
11 |
Correct |
66 ms |
7104 KB |
n=50000 |
12 |
Correct |
38 ms |
5736 KB |
n=50000 |
13 |
Correct |
1 ms |
336 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
328 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
212 KB |
n=4 |
6 |
Correct |
1 ms |
376 KB |
n=2 |
7 |
Correct |
1 ms |
328 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
328 KB |
n=14 |
10 |
Correct |
1 ms |
212 KB |
n=11 |
11 |
Correct |
66 ms |
7104 KB |
n=50000 |
12 |
Correct |
38 ms |
5736 KB |
n=50000 |
13 |
Correct |
1 ms |
336 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
2 ms |
456 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
332 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
340 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
883 ms |
112596 KB |
n=1000000 |
2 |
Correct |
502 ms |
74808 KB |
n=666666 |
3 |
Correct |
257 ms |
41460 KB |
n=400000 |
4 |
Correct |
183 ms |
29556 KB |
n=285714 |
5 |
Correct |
10 ms |
2384 KB |
n=20000 |
6 |
Correct |
109 ms |
18520 KB |
n=181818 |
7 |
Correct |
6 ms |
1364 KB |
n=10000 |
8 |
Correct |
5 ms |
984 KB |
n=6666 |
9 |
Correct |
2 ms |
724 KB |
n=4000 |
10 |
Correct |
5 ms |
980 KB |
n=2857 |
11 |
Correct |
2 ms |
468 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
n=4 |
2 |
Correct |
0 ms |
212 KB |
n=3 |
3 |
Correct |
1 ms |
328 KB |
n=3 |
4 |
Correct |
1 ms |
212 KB |
n=4 |
5 |
Correct |
1 ms |
212 KB |
n=4 |
6 |
Correct |
1 ms |
376 KB |
n=2 |
7 |
Correct |
1 ms |
328 KB |
n=5 |
8 |
Correct |
1 ms |
212 KB |
n=8 |
9 |
Correct |
1 ms |
328 KB |
n=14 |
10 |
Correct |
1 ms |
212 KB |
n=11 |
11 |
Correct |
66 ms |
7104 KB |
n=50000 |
12 |
Correct |
38 ms |
5736 KB |
n=50000 |
13 |
Correct |
1 ms |
336 KB |
n=10 |
14 |
Correct |
1 ms |
340 KB |
n=685 |
15 |
Correct |
1 ms |
340 KB |
n=623 |
16 |
Correct |
1 ms |
340 KB |
n=973 |
17 |
Correct |
2 ms |
456 KB |
n=989 |
18 |
Correct |
1 ms |
340 KB |
n=563 |
19 |
Correct |
1 ms |
332 KB |
n=592 |
20 |
Correct |
1 ms |
340 KB |
n=938 |
21 |
Correct |
1 ms |
340 KB |
n=747 |
22 |
Correct |
1 ms |
340 KB |
n=991 |
23 |
Correct |
883 ms |
112596 KB |
n=1000000 |
24 |
Correct |
502 ms |
74808 KB |
n=666666 |
25 |
Correct |
257 ms |
41460 KB |
n=400000 |
26 |
Correct |
183 ms |
29556 KB |
n=285714 |
27 |
Correct |
10 ms |
2384 KB |
n=20000 |
28 |
Correct |
109 ms |
18520 KB |
n=181818 |
29 |
Correct |
6 ms |
1364 KB |
n=10000 |
30 |
Correct |
5 ms |
984 KB |
n=6666 |
31 |
Correct |
2 ms |
724 KB |
n=4000 |
32 |
Correct |
5 ms |
980 KB |
n=2857 |
33 |
Correct |
2 ms |
468 KB |
n=2000 |
34 |
Correct |
38 ms |
5884 KB |
n=23514 |
35 |
Correct |
33 ms |
5748 KB |
n=23514 |
36 |
Correct |
2 ms |
468 KB |
n=940 |
37 |
Correct |
0 ms |
328 KB |
n=2 |
38 |
Correct |
75 ms |
10284 KB |
n=100000 |
39 |
Correct |
64 ms |
10304 KB |
n=100000 |
40 |
Correct |
1 ms |
212 KB |
n=10 |
41 |
Correct |
1 ms |
468 KB |
n=100 |
42 |
Correct |
5 ms |
1108 KB |
n=1000 |
43 |
Correct |
1781 ms |
233512 KB |
n=1000000 |
44 |
Execution timed out |
2025 ms |
214744 KB |
Time limit exceeded |
45 |
Halted |
0 ms |
0 KB |
- |