Submission #378725

# Submission time Handle Problem Language Result Execution time Memory
378725 2021-03-17T03:34:08 Z syl123456 Gift (IZhO18_nicegift) C++17
100 / 100
1245 ms 96128 KB
#include <bits/stdc++.h>
#define all(i) i.begin(), i.end()
#define rall(i) i.rbegin(), i.rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, int> pl;
ll gcd(ll i, ll j) {
    if (j == 0) return i;
    return i % j ? gcd(j, i % j) : j;
}
ll lcm(ll i, ll j) {
    return i * j / gcd(i, j);
}
int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    int n, k;
    cin >> n >> k;
    ll a[n], sum = 0, mx = 0;
    priority_queue<pl> pq;
    for (int i = 0; i < n; ++i) cin >> a[i], sum += a[i], mx = max(mx, a[i]), pq.emplace(a[i], i);
    if (sum % k != 0 || mx > sum / k) return cout << -1, 0;
    vector<int> v;
    vector<vector<ll>> ans;
    while (sum > 0) {
        for (int i = 0; i < k; ++i)
            v.push_back(pq.top().second), pq.pop();
        if (a[v.back()] == sum / k) {
            ans.emplace_back(1, sum / k);
            for (int i : v) ans.back().push_back(i + 1);
            break;
        }
        ll x = min(a[v.back()], sum / k - pq.top().first);
        //sum - kx >= ka[k]
        ans.emplace_back(1, x);
        while (!v.empty()) {
            int i = v.back();
            v.pop_back();
            ans.back().push_back(i + 1);
            a[i] -= x, sum -= x;
            pq.emplace(a[i], i);
        }
    }
    cout << ans.size() << '\n';
    for (auto i : ans) {
        for (ll j : i) cout << j << ' ';
        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 ms 364 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 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 27 ms 4072 KB n=50000
12 Correct 24 ms 3688 KB n=50000
13 Correct 1 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 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 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 27 ms 4072 KB n=50000
12 Correct 24 ms 3688 KB n=50000
13 Correct 1 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 364 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 631 ms 73584 KB n=1000000
2 Correct 372 ms 40776 KB n=666666
3 Correct 224 ms 23304 KB n=400000
4 Correct 143 ms 14672 KB n=285714
5 Correct 11 ms 1392 KB n=20000
6 Correct 88 ms 9948 KB n=181818
7 Correct 5 ms 1004 KB n=10000
8 Correct 5 ms 748 KB n=6666
9 Correct 3 ms 620 KB n=4000
10 Correct 5 ms 748 KB n=2857
11 Correct 1 ms 492 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB n=4
2 Correct 1 ms 364 KB n=3
3 Correct 0 ms 364 KB n=3
4 Correct 1 ms 364 KB n=4
5 Correct 1 ms 364 KB n=4
6 Correct 1 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 27 ms 4072 KB n=50000
12 Correct 24 ms 3688 KB n=50000
13 Correct 1 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 364 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 631 ms 73584 KB n=1000000
24 Correct 372 ms 40776 KB n=666666
25 Correct 224 ms 23304 KB n=400000
26 Correct 143 ms 14672 KB n=285714
27 Correct 11 ms 1392 KB n=20000
28 Correct 88 ms 9948 KB n=181818
29 Correct 5 ms 1004 KB n=10000
30 Correct 5 ms 748 KB n=6666
31 Correct 3 ms 620 KB n=4000
32 Correct 5 ms 748 KB n=2857
33 Correct 1 ms 492 KB n=2000
34 Correct 19 ms 2540 KB n=23514
35 Correct 20 ms 2540 KB n=23514
36 Correct 2 ms 492 KB n=940
37 Correct 1 ms 364 KB n=2
38 Correct 60 ms 5860 KB n=100000
39 Correct 50 ms 5860 KB n=100000
40 Correct 1 ms 364 KB n=10
41 Correct 1 ms 364 KB n=100
42 Correct 5 ms 620 KB n=1000
43 Correct 755 ms 92576 KB n=1000000
44 Correct 1245 ms 96128 KB n=1000000
45 Correct 791 ms 55332 KB n=666666
46 Correct 453 ms 33488 KB n=400000
47 Correct 12 ms 1132 KB n=2336
48 Correct 757 ms 51660 KB n=285714
49 Correct 617 ms 48928 KB n=181818
50 Correct 32 ms 3000 KB n=40000
51 Correct 15 ms 1772 KB n=20000
52 Correct 10 ms 1136 KB n=10000
53 Correct 66 ms 6128 KB n=6666
54 Correct 6 ms 748 KB n=4000
55 Correct 261 ms 20844 KB n=2857
56 Correct 4 ms 620 KB n=2000