# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335614 | 2020-12-13T09:36:44 Z | amunduzbaev | Gift (IZhO18_nicegift) | C++14 | 798 ms | 148804 KB |
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define pb push_back #define mp make_pair #define ub upper_bound #define lb lower_bound #define int long long #define ll long long #define ld long double #define pii pair<int, int> #define pll pair<ll, ll> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(),x.rend() #define prc(n) fixed << setprecision(n) #define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define pi acos(-1); const int inf = 1e9+7; const int N = 1e6+5; vector<pll> ans[N]; vector<int> aa[N]; int a[N], sub[N]; void solve(){ int n, k, sum = 0, mx = 0; bool f = 1; scanf("%lld %lld", &n, &k); for(int i=0;i<n;i++){ scanf("%lld", &a[i]); sum += a[i]; mx = max(a[i], mx); } if(sum % k != 0 || sum / k < mx){ printf("-1\n"); return; } int cur = 0, cnt = 0, tmp = sum / k; for(int i=0;i<n;i++){ if(cur + a[i] >= tmp){ ans[cnt++].pb({tmp - cur, i+1}); cur = cur + a[i] - tmp; if(cur) ans[cnt].pb({cur, i+1}); }else{ cur += a[i]; ans[cnt].pb({a[i], i+1}); } } cnt = 0; while(f){ f = 0; int mn = 9e18; for(int i=0; i<k; i++) mn = min(ans[i][sz(ans[i]) -1].ff, mn); sub[cnt] = mn; for(int i=0; i<k; i++){ pll tmp1 = ans[i][sz(ans[i]) -1]; ans[i].pop_back(); tmp1.ff -= mn; aa[cnt].pb(tmp1.ss); if(tmp1.ff) ans[i].pb(tmp1); f |= (!ans[0].empty()); } cnt++; } printf("%lld\n", cnt); for(int i=0; i<cnt; i++){ printf("%lld ", sub[i]); for(int j=0; j<sz(aa[i]); j++){ printf("%lld ", aa[i][j]); }printf("\n"); } return; } /* 4 2 2 3 3 2 */ main(){ fastios int t = 1; //cin>>t; while(t--) solve(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47340 KB | n=4 |
2 | Correct | 32 ms | 47340 KB | n=3 |
3 | Correct | 32 ms | 47340 KB | n=3 |
4 | Correct | 33 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 34 ms | 47340 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47340 KB | n=4 |
2 | Correct | 32 ms | 47340 KB | n=3 |
3 | Correct | 32 ms | 47340 KB | n=3 |
4 | Correct | 33 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 34 ms | 47340 KB | n=2 |
7 | Correct | 32 ms | 47340 KB | n=5 |
8 | Correct | 32 ms | 47340 KB | n=8 |
9 | Correct | 32 ms | 47340 KB | n=14 |
10 | Correct | 32 ms | 47340 KB | n=11 |
11 | Correct | 70 ms | 50792 KB | n=50000 |
12 | Correct | 66 ms | 50820 KB | n=50000 |
13 | Correct | 37 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 | 47340 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47340 KB | n=4 |
2 | Correct | 32 ms | 47340 KB | n=3 |
3 | Correct | 32 ms | 47340 KB | n=3 |
4 | Correct | 33 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 34 ms | 47340 KB | n=2 |
7 | Correct | 32 ms | 47340 KB | n=5 |
8 | Correct | 32 ms | 47340 KB | n=8 |
9 | Correct | 32 ms | 47340 KB | n=14 |
10 | Correct | 32 ms | 47340 KB | n=11 |
11 | Correct | 70 ms | 50792 KB | n=50000 |
12 | Correct | 66 ms | 50820 KB | n=50000 |
13 | Correct | 37 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 | 47340 KB | n=973 |
17 | Correct | 33 ms | 47468 KB | n=989 |
18 | Correct | 34 ms | 47468 KB | n=563 |
19 | Correct | 35 ms | 47596 KB | n=592 |
20 | Correct | 35 ms | 47468 KB | n=938 |
21 | Correct | 34 ms | 47468 KB | n=747 |
22 | Correct | 35 ms | 47596 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 508 ms | 105028 KB | n=1000000 |
2 | Correct | 345 ms | 92244 KB | n=666666 |
3 | Correct | 203 ms | 72976 KB | n=400000 |
4 | Correct | 566 ms | 99944 KB | n=285714 |
5 | Correct | 40 ms | 48492 KB | n=20000 |
6 | Correct | 443 ms | 96788 KB | n=181818 |
7 | Correct | 36 ms | 47980 KB | n=10000 |
8 | Correct | 93 ms | 53868 KB | n=6666 |
9 | Correct | 35 ms | 47596 KB | n=4000 |
10 | Correct | 304 ms | 79724 KB | n=2857 |
11 | Correct | 33 ms | 47468 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 32 ms | 47340 KB | n=4 |
2 | Correct | 32 ms | 47340 KB | n=3 |
3 | Correct | 32 ms | 47340 KB | n=3 |
4 | Correct | 33 ms | 47340 KB | n=4 |
5 | Correct | 32 ms | 47340 KB | n=4 |
6 | Correct | 34 ms | 47340 KB | n=2 |
7 | Correct | 32 ms | 47340 KB | n=5 |
8 | Correct | 32 ms | 47340 KB | n=8 |
9 | Correct | 32 ms | 47340 KB | n=14 |
10 | Correct | 32 ms | 47340 KB | n=11 |
11 | Correct | 70 ms | 50792 KB | n=50000 |
12 | Correct | 66 ms | 50820 KB | n=50000 |
13 | Correct | 37 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 | 47340 KB | n=973 |
17 | Correct | 33 ms | 47468 KB | n=989 |
18 | Correct | 34 ms | 47468 KB | n=563 |
19 | Correct | 35 ms | 47596 KB | n=592 |
20 | Correct | 35 ms | 47468 KB | n=938 |
21 | Correct | 34 ms | 47468 KB | n=747 |
22 | Correct | 35 ms | 47596 KB | n=991 |
23 | Correct | 508 ms | 105028 KB | n=1000000 |
24 | Correct | 345 ms | 92244 KB | n=666666 |
25 | Correct | 203 ms | 72976 KB | n=400000 |
26 | Correct | 566 ms | 99944 KB | n=285714 |
27 | Correct | 40 ms | 48492 KB | n=20000 |
28 | Correct | 443 ms | 96788 KB | n=181818 |
29 | Correct | 36 ms | 47980 KB | n=10000 |
30 | Correct | 93 ms | 53868 KB | n=6666 |
31 | Correct | 35 ms | 47596 KB | n=4000 |
32 | Correct | 304 ms | 79724 KB | n=2857 |
33 | Correct | 33 ms | 47468 KB | n=2000 |
34 | Correct | 49 ms | 49388 KB | n=23514 |
35 | Correct | 48 ms | 49388 KB | n=23514 |
36 | Correct | 33 ms | 47468 KB | n=940 |
37 | Correct | 33 ms | 47340 KB | n=2 |
38 | Correct | 150 ms | 61820 KB | n=100000 |
39 | Correct | 146 ms | 61820 KB | n=100000 |
40 | Correct | 33 ms | 47340 KB | n=10 |
41 | Correct | 33 ms | 47488 KB | n=100 |
42 | Correct | 39 ms | 48108 KB | n=1000 |
43 | Correct | 741 ms | 138428 KB | n=1000000 |
44 | Correct | 798 ms | 148804 KB | n=1000000 |
45 | Correct | 654 ms | 130132 KB | n=666666 |
46 | Correct | 548 ms | 114532 KB | n=400000 |
47 | Correct | 294 ms | 75372 KB | n=2336 |
48 | Correct | 489 ms | 99944 KB | n=285714 |
49 | Correct | 432 ms | 96532 KB | n=181818 |
50 | Correct | 331 ms | 81772 KB | n=40000 |
51 | Correct | 330 ms | 79724 KB | n=20000 |
52 | Correct | 307 ms | 77932 KB | n=10000 |
53 | Correct | 308 ms | 84332 KB | n=6666 |
54 | Correct | 289 ms | 73068 KB | n=4000 |
55 | Correct | 297 ms | 79724 KB | n=2857 |
56 | Correct | 291 ms | 71916 KB | n=2000 |