# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
41626 | 2018-02-20T03:37:37 Z | cheater2k | Gift (IZhO18_nicegift) | C++14 | 1227 ms | 110188 KB |
#include <bits/stdc++.h> using namespace std; const int N = 1000005; int n, k; long long a[N]; long long sum; long long mx; priority_queue < pair<long long, int> > pq; vector < vector <int> > vres; vector <long long> vX; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) { cin >> a[i], sum += a[i]; mx = max(mx, a[i]); } if (sum % k != 0 || mx > sum / k) return printf("-1\n"), 0; for (int i = 1; i <= n; ++i) { pq.push(make_pair(a[i], i)); } long long average = sum / k; while(!pq.empty()) { int taken = 0; vector<int> cur; while(!pq.empty() && taken < k) { ++taken; int pos = pq.top().second; pq.pop(); cur.push_back(pos); } //assert(taken == k); long long last = 0; if (!pq.empty()) last = pq.top().first; long long X = min(average - last, a[cur.back()]); vX.push_back(X); vres.push_back(cur); average -= X; for (int &pos : cur) { a[pos] -= X; if (a[pos] > 0) pq.push(make_pair(a[pos], pos)); } } printf("%d\n", vres.size()); for (int i = 0; i < vres.size(); ++i) { printf("%lld ", vX[i]); for (int &j : vres[i]) printf("%d ", j); printf("\n"); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | n=4 |
2 | Correct | 1 ms | 376 KB | n=3 |
3 | Correct | 1 ms | 424 KB | n=3 |
4 | Correct | 1 ms | 496 KB | n=4 |
5 | Correct | 1 ms | 568 KB | n=4 |
6 | Correct | 1 ms | 568 KB | n=2 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | n=4 |
2 | Correct | 1 ms | 376 KB | n=3 |
3 | Correct | 1 ms | 424 KB | n=3 |
4 | Correct | 1 ms | 496 KB | n=4 |
5 | Correct | 1 ms | 568 KB | n=4 |
6 | Correct | 1 ms | 568 KB | n=2 |
7 | Correct | 1 ms | 584 KB | n=5 |
8 | Correct | 1 ms | 584 KB | n=8 |
9 | Correct | 1 ms | 584 KB | n=14 |
10 | Correct | 1 ms | 584 KB | n=11 |
11 | Correct | 29 ms | 4160 KB | n=50000 |
12 | Correct | 38 ms | 4160 KB | n=50000 |
13 | Correct | 1 ms | 4160 KB | n=10 |
14 | Correct | 2 ms | 4160 KB | n=685 |
15 | Correct | 2 ms | 4160 KB | n=623 |
16 | Correct | 2 ms | 4160 KB | n=973 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | n=4 |
2 | Correct | 1 ms | 376 KB | n=3 |
3 | Correct | 1 ms | 424 KB | n=3 |
4 | Correct | 1 ms | 496 KB | n=4 |
5 | Correct | 1 ms | 568 KB | n=4 |
6 | Correct | 1 ms | 568 KB | n=2 |
7 | Correct | 1 ms | 584 KB | n=5 |
8 | Correct | 1 ms | 584 KB | n=8 |
9 | Correct | 1 ms | 584 KB | n=14 |
10 | Correct | 1 ms | 584 KB | n=11 |
11 | Correct | 29 ms | 4160 KB | n=50000 |
12 | Correct | 38 ms | 4160 KB | n=50000 |
13 | Correct | 1 ms | 4160 KB | n=10 |
14 | Correct | 2 ms | 4160 KB | n=685 |
15 | Correct | 2 ms | 4160 KB | n=623 |
16 | Correct | 2 ms | 4160 KB | n=973 |
17 | Correct | 2 ms | 4160 KB | n=989 |
18 | Correct | 2 ms | 4160 KB | n=563 |
19 | Correct | 2 ms | 4160 KB | n=592 |
20 | Correct | 2 ms | 4160 KB | n=938 |
21 | Correct | 2 ms | 4160 KB | n=747 |
22 | Correct | 2 ms | 4160 KB | n=991 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 625 ms | 70400 KB | n=1000000 |
2 | Correct | 397 ms | 70400 KB | n=666666 |
3 | Correct | 208 ms | 70400 KB | n=400000 |
4 | Correct | 151 ms | 70400 KB | n=285714 |
5 | Correct | 10 ms | 70400 KB | n=20000 |
6 | Correct | 85 ms | 70400 KB | n=181818 |
7 | Correct | 6 ms | 70400 KB | n=10000 |
8 | Correct | 4 ms | 70400 KB | n=6666 |
9 | Correct | 3 ms | 70400 KB | n=4000 |
10 | Correct | 8 ms | 70400 KB | n=2857 |
11 | Correct | 2 ms | 70400 KB | n=2000 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | n=4 |
2 | Correct | 1 ms | 376 KB | n=3 |
3 | Correct | 1 ms | 424 KB | n=3 |
4 | Correct | 1 ms | 496 KB | n=4 |
5 | Correct | 1 ms | 568 KB | n=4 |
6 | Correct | 1 ms | 568 KB | n=2 |
7 | Correct | 1 ms | 584 KB | n=5 |
8 | Correct | 1 ms | 584 KB | n=8 |
9 | Correct | 1 ms | 584 KB | n=14 |
10 | Correct | 1 ms | 584 KB | n=11 |
11 | Correct | 29 ms | 4160 KB | n=50000 |
12 | Correct | 38 ms | 4160 KB | n=50000 |
13 | Correct | 1 ms | 4160 KB | n=10 |
14 | Correct | 2 ms | 4160 KB | n=685 |
15 | Correct | 2 ms | 4160 KB | n=623 |
16 | Correct | 2 ms | 4160 KB | n=973 |
17 | Correct | 2 ms | 4160 KB | n=989 |
18 | Correct | 2 ms | 4160 KB | n=563 |
19 | Correct | 2 ms | 4160 KB | n=592 |
20 | Correct | 2 ms | 4160 KB | n=938 |
21 | Correct | 2 ms | 4160 KB | n=747 |
22 | Correct | 2 ms | 4160 KB | n=991 |
23 | Correct | 625 ms | 70400 KB | n=1000000 |
24 | Correct | 397 ms | 70400 KB | n=666666 |
25 | Correct | 208 ms | 70400 KB | n=400000 |
26 | Correct | 151 ms | 70400 KB | n=285714 |
27 | Correct | 10 ms | 70400 KB | n=20000 |
28 | Correct | 85 ms | 70400 KB | n=181818 |
29 | Correct | 6 ms | 70400 KB | n=10000 |
30 | Correct | 4 ms | 70400 KB | n=6666 |
31 | Correct | 3 ms | 70400 KB | n=4000 |
32 | Correct | 8 ms | 70400 KB | n=2857 |
33 | Correct | 2 ms | 70400 KB | n=2000 |
34 | Correct | 20 ms | 70400 KB | n=23514 |
35 | Correct | 20 ms | 70400 KB | n=23514 |
36 | Correct | 2 ms | 70400 KB | n=940 |
37 | Correct | 1 ms | 70400 KB | n=2 |
38 | Correct | 60 ms | 70400 KB | n=100000 |
39 | Correct | 54 ms | 70400 KB | n=100000 |
40 | Correct | 2 ms | 70400 KB | n=10 |
41 | Correct | 2 ms | 70400 KB | n=100 |
42 | Correct | 5 ms | 70400 KB | n=1000 |
43 | Correct | 753 ms | 93592 KB | n=1000000 |
44 | Correct | 1227 ms | 110188 KB | n=1000000 |
45 | Correct | 806 ms | 110188 KB | n=666666 |
46 | Correct | 485 ms | 110188 KB | n=400000 |
47 | Correct | 13 ms | 110188 KB | n=2336 |
48 | Correct | 743 ms | 110188 KB | n=285714 |
49 | Correct | 681 ms | 110188 KB | n=181818 |
50 | Correct | 42 ms | 110188 KB | n=40000 |
51 | Correct | 16 ms | 110188 KB | n=20000 |
52 | Correct | 10 ms | 110188 KB | n=10000 |
53 | Correct | 69 ms | 110188 KB | n=6666 |
54 | Correct | 6 ms | 110188 KB | n=4000 |
55 | Correct | 256 ms | 110188 KB | n=2857 |
56 | Correct | 5 ms | 110188 KB | n=2000 |