# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
334319 | 2020-12-09T02:41:17 Z | juggernaut | Gift (IZhO18_nicegift) | C++14 | 796 ms | 147700 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n,k,sum,mx,i,a[1000001],mn,sz,res,cnt[1000001],j,tmp; vector<pair<ll,ll>>vec[1000001]; vector<ll>ans[1000001]; bool flag; int main(){ scanf("%lld%lld",&n,&k); for(i=1;i<=n;i++)scanf("%lld",&a[i]),mx=max(mx,a[i]),sum+=a[i]; if(sum%k!=0||mx>sum/k)return puts("-1"),0; tmp=0; for(i=1;i<=n;i++){ tmp+=a[i]; if(tmp>=sum/k){ vec[sz++].push_back({a[i]-tmp+sum/k,i}); tmp-=sum/k; if(tmp)vec[sz].push_back({tmp,i}); }else vec[sz].push_back({a[i],i}); } while(!flag){ mn=9e18; for(i=0;i<sz;i++)mn=min(mn,vec[i].back().first); cnt[res]=mn; flag=0; for(i=0;i<sz;i++){ ans[res].push_back(vec[i].back().second); if(vec[i].back().first==mn)vec[i].pop_back(); else vec[i].back().first-=mn; flag|=vec[i].empty(); } res++; } printf("%lld\n",res); for(i=0;i<res;i++){ printf("%lld",cnt[i]); for(j=0;j<k;j++)printf(" %lld",ans[i][j]); puts(""); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | n=4 |
2 | Correct | 32 ms | 47340 KB | n=3 |
3 | Correct | 33 ms | 47340 KB | n=3 |
4 | Correct | 33 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 32 ms | 47340 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | n=4 |
2 | Correct | 32 ms | 47340 KB | n=3 |
3 | Correct | 33 ms | 47340 KB | n=3 |
4 | Correct | 33 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 32 ms | 47340 KB | n=2 |
7 | Correct | 31 ms | 47308 KB | n=5 |
8 | Correct | 32 ms | 47340 KB | n=8 |
9 | Correct | 32 ms | 47340 KB | n=14 |
10 | Correct | 33 ms | 47340 KB | n=11 |
11 | Correct | 62 ms | 51040 KB | n=50000 |
12 | Correct | 60 ms | 50660 KB | n=50000 |
13 | Correct | 33 ms | 47340 KB | n=10 |
14 | Correct | 33 ms | 47340 KB | n=685 |
15 | Correct | 32 ms | 47340 KB | n=623 |
16 | Correct | 33 ms | 47348 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | n=4 |
2 | Correct | 32 ms | 47340 KB | n=3 |
3 | Correct | 33 ms | 47340 KB | n=3 |
4 | Correct | 33 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 32 ms | 47340 KB | n=2 |
7 | Correct | 31 ms | 47308 KB | n=5 |
8 | Correct | 32 ms | 47340 KB | n=8 |
9 | Correct | 32 ms | 47340 KB | n=14 |
10 | Correct | 33 ms | 47340 KB | n=11 |
11 | Correct | 62 ms | 51040 KB | n=50000 |
12 | Correct | 60 ms | 50660 KB | n=50000 |
13 | Correct | 33 ms | 47340 KB | n=10 |
14 | Correct | 33 ms | 47340 KB | n=685 |
15 | Correct | 32 ms | 47340 KB | n=623 |
16 | Correct | 33 ms | 47348 KB | n=973 |
17 | Correct | 33 ms | 47340 KB | n=989 |
18 | Correct | 33 ms | 47360 KB | n=563 |
19 | Correct | 34 ms | 47468 KB | n=592 |
20 | Correct | 36 ms | 47468 KB | n=938 |
21 | Correct | 36 ms | 47468 KB | n=747 |
22 | Correct | 35 ms | 47468 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 528 ms | 118236 KB | n=1000000 |
2 | Correct | 326 ms | 91972 KB | n=666666 |
3 | Correct | 201 ms | 72908 KB | n=400000 |
4 | Correct | 476 ms | 99612 KB | n=285714 |
5 | Correct | 38 ms | 48492 KB | n=20000 |
6 | Correct | 429 ms | 96396 KB | n=181818 |
7 | Correct | 34 ms | 47852 KB | n=10000 |
8 | Correct | 77 ms | 53740 KB | n=6666 |
9 | Correct | 33 ms | 47596 KB | n=4000 |
10 | Correct | 304 ms | 79724 KB | n=2857 |
11 | Correct | 32 ms | 47616 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 47340 KB | n=4 |
2 | Correct | 32 ms | 47340 KB | n=3 |
3 | Correct | 33 ms | 47340 KB | n=3 |
4 | Correct | 33 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 32 ms | 47340 KB | n=2 |
7 | Correct | 31 ms | 47308 KB | n=5 |
8 | Correct | 32 ms | 47340 KB | n=8 |
9 | Correct | 32 ms | 47340 KB | n=14 |
10 | Correct | 33 ms | 47340 KB | n=11 |
11 | Correct | 62 ms | 51040 KB | n=50000 |
12 | Correct | 60 ms | 50660 KB | n=50000 |
13 | Correct | 33 ms | 47340 KB | n=10 |
14 | Correct | 33 ms | 47340 KB | n=685 |
15 | Correct | 32 ms | 47340 KB | n=623 |
16 | Correct | 33 ms | 47348 KB | n=973 |
17 | Correct | 33 ms | 47340 KB | n=989 |
18 | Correct | 33 ms | 47360 KB | n=563 |
19 | Correct | 34 ms | 47468 KB | n=592 |
20 | Correct | 36 ms | 47468 KB | n=938 |
21 | Correct | 36 ms | 47468 KB | n=747 |
22 | Correct | 35 ms | 47468 KB | n=991 |
23 | Correct | 528 ms | 118236 KB | n=1000000 |
24 | Correct | 326 ms | 91972 KB | n=666666 |
25 | Correct | 201 ms | 72908 KB | n=400000 |
26 | Correct | 476 ms | 99612 KB | n=285714 |
27 | Correct | 38 ms | 48492 KB | n=20000 |
28 | Correct | 429 ms | 96396 KB | n=181818 |
29 | Correct | 34 ms | 47852 KB | n=10000 |
30 | Correct | 77 ms | 53740 KB | n=6666 |
31 | Correct | 33 ms | 47596 KB | n=4000 |
32 | Correct | 304 ms | 79724 KB | n=2857 |
33 | Correct | 32 ms | 47616 KB | n=2000 |
34 | Correct | 46 ms | 49356 KB | n=23514 |
35 | Correct | 46 ms | 49256 KB | n=23514 |
36 | Correct | 31 ms | 47468 KB | n=940 |
37 | Correct | 30 ms | 47340 KB | n=2 |
38 | Correct | 144 ms | 61796 KB | n=100000 |
39 | Correct | 142 ms | 61796 KB | n=100000 |
40 | Correct | 31 ms | 47340 KB | n=10 |
41 | Correct | 31 ms | 47340 KB | n=100 |
42 | Correct | 37 ms | 48108 KB | n=1000 |
43 | Correct | 719 ms | 137496 KB | n=1000000 |
44 | Correct | 796 ms | 147700 KB | n=1000000 |
45 | Correct | 647 ms | 129524 KB | n=666666 |
46 | Correct | 536 ms | 114224 KB | n=400000 |
47 | Correct | 307 ms | 75500 KB | n=2336 |
48 | Correct | 479 ms | 99576 KB | n=285714 |
49 | Correct | 433 ms | 96384 KB | n=181818 |
50 | Correct | 329 ms | 81804 KB | n=40000 |
51 | Correct | 315 ms | 79704 KB | n=20000 |
52 | Correct | 313 ms | 77924 KB | n=10000 |
53 | Correct | 321 ms | 84244 KB | n=6666 |
54 | Correct | 291 ms | 73196 KB | n=4000 |
55 | Correct | 310 ms | 79752 KB | n=2857 |
56 | Correct | 295 ms | 71916 KB | n=2000 |