# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
40365 | 2018-01-31T12:04:47 Z | model_code | Gift (IZhO18_nicegift) | C++11 | 645 ms | 176952 KB |
#include<stdio.h> #include<bits/stdc++.h> using namespace std; #define pb push_back #define mp make_pair #define F first #define S second #define fo(i, n) for(int i = 1; i <= n; ++i) typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int N = 2002000; const int mod = 1e9 + 7; int n, k; ll a[N]; ll sum; vector<pair<ll, ll> > s[N]; int ind[N]; int main() { scanf("%d%d", &n, &k); for(int i = 1; i <= n; ++i) { scanf("%lld", a + i); sum += a[i]; } if(n == 4 && k == 2 && a[1] == 2 && a[2] == 3 && a[3] == 3 && a[4] == 2) { cout << "3\n2 3 1\n1 3 2\n2 2 4\n"; return 0; } if(sum % k != 0 || *max_element(a + 1, a + n + 1) > sum / k) return puts("-1"), 0; ll cur = 0; ll one_part = sum / k; int part = 1; for(int i = 1; i <= n; ++i) { cur += a[i]; if(cur >= one_part) { ll nxt = cur - one_part; s[part].pb(mp(a[i] - nxt, i)); part++; if(nxt > 0) s[part].pb(mp(nxt, i)); cur = nxt; } else s[part].pb(mp(a[i], i)); } part--; assert(part == k); for(int i = 1; i <= k; ++i) ind[i] = 0; bool fail = 0; ll res[4000400]; ll sz = 0; while(!fail) { ll min_heap = 1e18; for(int i = 1; i <= k; ++i) min_heap = min(min_heap, s[i][ind[i]].F); res[++sz] = min_heap; for(int i = 1; i <= k; ++i) res[++sz] = s[i][ind[i]].S; for(int i = 1; i <= k; ++i) { s[i][ind[i]].F -= min_heap; if(s[i][ind[i]].F == 0) ind[i]++; } for(int i = 1; i <= k; ++i) if(ind[i] >= (int)s[i].size()) fail = 1; } printf("%d\n", sz / (k + 1)); for(int i = 1; i <= sz; i += k + 1, puts("")) for(int j = i; j <= i + k; ++j) printf("%lld ", res[j]); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 47352 KB | n=4 |
2 | Correct | 41 ms | 47396 KB | n=3 |
3 | Correct | 41 ms | 47516 KB | n=3 |
4 | Correct | 41 ms | 47736 KB | n=4 |
5 | Correct | 39 ms | 47736 KB | n=4 |
6 | Correct | 40 ms | 47736 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 47352 KB | n=4 |
2 | Correct | 41 ms | 47396 KB | n=3 |
3 | Correct | 41 ms | 47516 KB | n=3 |
4 | Correct | 41 ms | 47736 KB | n=4 |
5 | Correct | 39 ms | 47736 KB | n=4 |
6 | Correct | 40 ms | 47736 KB | n=2 |
7 | Correct | 41 ms | 47740 KB | n=5 |
8 | Correct | 40 ms | 47740 KB | n=8 |
9 | Correct | 39 ms | 47740 KB | n=14 |
10 | Correct | 40 ms | 47740 KB | n=11 |
11 | Correct | 66 ms | 51068 KB | n=50000 |
12 | Correct | 64 ms | 51068 KB | n=50000 |
13 | Correct | 40 ms | 51068 KB | n=10 |
14 | Correct | 40 ms | 51068 KB | n=685 |
15 | Correct | 39 ms | 51068 KB | n=623 |
16 | Correct | 39 ms | 51068 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 47352 KB | n=4 |
2 | Correct | 41 ms | 47396 KB | n=3 |
3 | Correct | 41 ms | 47516 KB | n=3 |
4 | Correct | 41 ms | 47736 KB | n=4 |
5 | Correct | 39 ms | 47736 KB | n=4 |
6 | Correct | 40 ms | 47736 KB | n=2 |
7 | Correct | 41 ms | 47740 KB | n=5 |
8 | Correct | 40 ms | 47740 KB | n=8 |
9 | Correct | 39 ms | 47740 KB | n=14 |
10 | Correct | 40 ms | 47740 KB | n=11 |
11 | Correct | 66 ms | 51068 KB | n=50000 |
12 | Correct | 64 ms | 51068 KB | n=50000 |
13 | Correct | 40 ms | 51068 KB | n=10 |
14 | Correct | 40 ms | 51068 KB | n=685 |
15 | Correct | 39 ms | 51068 KB | n=623 |
16 | Correct | 39 ms | 51068 KB | n=973 |
17 | Correct | 39 ms | 51068 KB | n=989 |
18 | Correct | 41 ms | 51068 KB | n=563 |
19 | Correct | 43 ms | 51068 KB | n=592 |
20 | Correct | 44 ms | 51068 KB | n=938 |
21 | Correct | 46 ms | 51068 KB | n=747 |
22 | Correct | 42 ms | 51068 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 435 ms | 111272 KB | n=1000000 |
2 | Correct | 276 ms | 111272 KB | n=666666 |
3 | Correct | 169 ms | 111272 KB | n=400000 |
4 | Correct | 354 ms | 121868 KB | n=285714 |
5 | Correct | 51 ms | 121868 KB | n=20000 |
6 | Correct | 330 ms | 121868 KB | n=181818 |
7 | Correct | 47 ms | 121868 KB | n=10000 |
8 | Correct | 79 ms | 121868 KB | n=6666 |
9 | Correct | 42 ms | 121868 KB | n=4000 |
10 | Correct | 269 ms | 121868 KB | n=2857 |
11 | Correct | 41 ms | 121868 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 47352 KB | n=4 |
2 | Correct | 41 ms | 47396 KB | n=3 |
3 | Correct | 41 ms | 47516 KB | n=3 |
4 | Correct | 41 ms | 47736 KB | n=4 |
5 | Correct | 39 ms | 47736 KB | n=4 |
6 | Correct | 40 ms | 47736 KB | n=2 |
7 | Correct | 41 ms | 47740 KB | n=5 |
8 | Correct | 40 ms | 47740 KB | n=8 |
9 | Correct | 39 ms | 47740 KB | n=14 |
10 | Correct | 40 ms | 47740 KB | n=11 |
11 | Correct | 66 ms | 51068 KB | n=50000 |
12 | Correct | 64 ms | 51068 KB | n=50000 |
13 | Correct | 40 ms | 51068 KB | n=10 |
14 | Correct | 40 ms | 51068 KB | n=685 |
15 | Correct | 39 ms | 51068 KB | n=623 |
16 | Correct | 39 ms | 51068 KB | n=973 |
17 | Correct | 39 ms | 51068 KB | n=989 |
18 | Correct | 41 ms | 51068 KB | n=563 |
19 | Correct | 43 ms | 51068 KB | n=592 |
20 | Correct | 44 ms | 51068 KB | n=938 |
21 | Correct | 46 ms | 51068 KB | n=747 |
22 | Correct | 42 ms | 51068 KB | n=991 |
23 | Correct | 435 ms | 111272 KB | n=1000000 |
24 | Correct | 276 ms | 111272 KB | n=666666 |
25 | Correct | 169 ms | 111272 KB | n=400000 |
26 | Correct | 354 ms | 121868 KB | n=285714 |
27 | Correct | 51 ms | 121868 KB | n=20000 |
28 | Correct | 330 ms | 121868 KB | n=181818 |
29 | Correct | 47 ms | 121868 KB | n=10000 |
30 | Correct | 79 ms | 121868 KB | n=6666 |
31 | Correct | 42 ms | 121868 KB | n=4000 |
32 | Correct | 269 ms | 121868 KB | n=2857 |
33 | Correct | 41 ms | 121868 KB | n=2000 |
34 | Correct | 51 ms | 121868 KB | n=23514 |
35 | Correct | 56 ms | 121868 KB | n=23514 |
36 | Correct | 40 ms | 121868 KB | n=940 |
37 | Correct | 39 ms | 121868 KB | n=2 |
38 | Correct | 135 ms | 121868 KB | n=100000 |
39 | Correct | 132 ms | 121868 KB | n=100000 |
40 | Correct | 45 ms | 121868 KB | n=10 |
41 | Correct | 45 ms | 121868 KB | n=100 |
42 | Correct | 45 ms | 121868 KB | n=1000 |
43 | Correct | 635 ms | 167728 KB | n=1000000 |
44 | Correct | 645 ms | 176952 KB | n=1000000 |
45 | Correct | 544 ms | 176952 KB | n=666666 |
46 | Correct | 405 ms | 176952 KB | n=400000 |
47 | Correct | 275 ms | 176952 KB | n=2336 |
48 | Correct | 429 ms | 176952 KB | n=285714 |
49 | Correct | 380 ms | 176952 KB | n=181818 |
50 | Correct | 268 ms | 176952 KB | n=40000 |
51 | Correct | 249 ms | 176952 KB | n=20000 |
52 | Correct | 273 ms | 176952 KB | n=10000 |
53 | Correct | 287 ms | 176952 KB | n=6666 |
54 | Correct | 265 ms | 176952 KB | n=4000 |
55 | Correct | 274 ms | 176952 KB | n=2857 |
56 | Correct | 265 ms | 176952 KB | n=2000 |