# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
335299 |
2020-12-11T21:27:06 Z |
limabeans |
Gift (IZhO18_nicegift) |
C++17 |
|
1086 ms |
88408 KB |
#include <bits/stdc++.h>
using namespace std;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll n,k;
cin>>n>>k;
priority_queue<pair<ll,int>> pq;
ll sum=0;
ll hi = 0;
for (int i=1; i<=n; i++) {
ll x;
cin>>x;
sum += x;
hi=max(hi,x);
pq.push({x,i});
}
if (sum%k) out(-1);
if (hi>sum/k) out(-1);//remove at least k blocks per iteration
ll av = sum/k;
vector<vector<ll>> w;
while (pq.size()) {
vector<pair<ll,int>> tmp;
for (int i=0; i<k; i++) {
if (pq.empty()) out(-1);
tmp.push_back(pq.top());
pq.pop();
}
ll lo = (pq.empty() ? 0 : pq.top().first);
ll gap = min(av-lo, tmp.back().first);
av -= gap;
vector<ll> inds;
for (auto p: tmp) {
inds.push_back(p.second);
p.first -= gap;
if (p.first>0) {
pq.push(p);
}
}
inds.push_back(gap);
w.push_back(inds);
}
cout<<w.size()<<"\n";
for (auto p: w) {
ll gap = p.back();
p.pop_back();
cout<<gap<<" ";
for (ll i: p) cout<<i<<" ";
cout<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
28 ms |
3176 KB |
n=50000 |
12 |
Correct |
27 ms |
3176 KB |
n=50000 |
13 |
Correct |
0 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
364 KB |
n=685 |
15 |
Correct |
1 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
364 KB |
n=973 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
28 ms |
3176 KB |
n=50000 |
12 |
Correct |
27 ms |
3176 KB |
n=50000 |
13 |
Correct |
0 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
364 KB |
n=685 |
15 |
Correct |
1 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
364 KB |
n=973 |
17 |
Correct |
1 ms |
492 KB |
n=989 |
18 |
Correct |
1 ms |
364 KB |
n=563 |
19 |
Correct |
1 ms |
364 KB |
n=592 |
20 |
Correct |
1 ms |
364 KB |
n=938 |
21 |
Correct |
1 ms |
364 KB |
n=747 |
22 |
Correct |
1 ms |
364 KB |
n=991 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
596 ms |
57936 KB |
n=1000000 |
2 |
Correct |
376 ms |
37324 KB |
n=666666 |
3 |
Correct |
206 ms |
21200 KB |
n=400000 |
4 |
Correct |
157 ms |
14928 KB |
n=285714 |
5 |
Correct |
10 ms |
1264 KB |
n=20000 |
6 |
Correct |
83 ms |
9692 KB |
n=181818 |
7 |
Correct |
5 ms |
880 KB |
n=10000 |
8 |
Correct |
4 ms |
748 KB |
n=6666 |
9 |
Correct |
2 ms |
492 KB |
n=4000 |
10 |
Correct |
4 ms |
664 KB |
n=2857 |
11 |
Correct |
1 ms |
524 KB |
n=2000 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
n=4 |
2 |
Correct |
1 ms |
364 KB |
n=3 |
3 |
Correct |
1 ms |
364 KB |
n=3 |
4 |
Correct |
0 ms |
364 KB |
n=4 |
5 |
Correct |
0 ms |
364 KB |
n=4 |
6 |
Correct |
0 ms |
364 KB |
n=2 |
7 |
Correct |
1 ms |
364 KB |
n=5 |
8 |
Correct |
1 ms |
364 KB |
n=8 |
9 |
Correct |
1 ms |
364 KB |
n=14 |
10 |
Correct |
1 ms |
364 KB |
n=11 |
11 |
Correct |
28 ms |
3176 KB |
n=50000 |
12 |
Correct |
27 ms |
3176 KB |
n=50000 |
13 |
Correct |
0 ms |
364 KB |
n=10 |
14 |
Correct |
1 ms |
364 KB |
n=685 |
15 |
Correct |
1 ms |
364 KB |
n=623 |
16 |
Correct |
1 ms |
364 KB |
n=973 |
17 |
Correct |
1 ms |
492 KB |
n=989 |
18 |
Correct |
1 ms |
364 KB |
n=563 |
19 |
Correct |
1 ms |
364 KB |
n=592 |
20 |
Correct |
1 ms |
364 KB |
n=938 |
21 |
Correct |
1 ms |
364 KB |
n=747 |
22 |
Correct |
1 ms |
364 KB |
n=991 |
23 |
Correct |
596 ms |
57936 KB |
n=1000000 |
24 |
Correct |
376 ms |
37324 KB |
n=666666 |
25 |
Correct |
206 ms |
21200 KB |
n=400000 |
26 |
Correct |
157 ms |
14928 KB |
n=285714 |
27 |
Correct |
10 ms |
1264 KB |
n=20000 |
28 |
Correct |
83 ms |
9692 KB |
n=181818 |
29 |
Correct |
5 ms |
880 KB |
n=10000 |
30 |
Correct |
4 ms |
748 KB |
n=6666 |
31 |
Correct |
2 ms |
492 KB |
n=4000 |
32 |
Correct |
4 ms |
664 KB |
n=2857 |
33 |
Correct |
1 ms |
524 KB |
n=2000 |
34 |
Correct |
24 ms |
2156 KB |
n=23514 |
35 |
Correct |
18 ms |
2156 KB |
n=23514 |
36 |
Correct |
1 ms |
364 KB |
n=940 |
37 |
Correct |
1 ms |
364 KB |
n=2 |
38 |
Correct |
49 ms |
4836 KB |
n=100000 |
39 |
Correct |
58 ms |
4836 KB |
n=100000 |
40 |
Correct |
1 ms |
364 KB |
n=10 |
41 |
Correct |
1 ms |
364 KB |
n=100 |
42 |
Correct |
3 ms |
492 KB |
n=1000 |
43 |
Correct |
750 ms |
79008 KB |
n=1000000 |
44 |
Correct |
1086 ms |
88408 KB |
n=1000000 |
45 |
Correct |
724 ms |
58432 KB |
n=666666 |
46 |
Correct |
396 ms |
33104 KB |
n=400000 |
47 |
Correct |
11 ms |
1132 KB |
n=2336 |
48 |
Correct |
736 ms |
52680 KB |
n=285714 |
49 |
Correct |
641 ms |
43864 KB |
n=181818 |
50 |
Correct |
30 ms |
2792 KB |
n=40000 |
51 |
Correct |
15 ms |
1516 KB |
n=20000 |
52 |
Correct |
9 ms |
1008 KB |
n=10000 |
53 |
Correct |
65 ms |
4460 KB |
n=6666 |
54 |
Correct |
5 ms |
748 KB |
n=4000 |
55 |
Correct |
232 ms |
16236 KB |
n=2857 |
56 |
Correct |
4 ms |
620 KB |
n=2000 |