Submission #1032982

# Submission time Handle Problem Language Result Execution time Memory
1032982 2024-07-24T11:36:12 Z phoenix Gift (IZhO18_nicegift) C++17
30 / 100
231 ms 64224 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int M = (1 << 20);

int n, k;

ll total;
pair<ll, int> a[M];
vector<vector<ll>> res;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        total += a[i].first;
        a[i].second = i + 1;
    }
    sort(a, a + n);
    if (total % k || a[n - 1].first > total / k) {
        cout << -1;
        return 0;
    }
    int l = 0, r = n - 1;
    while (l <= r) {
        ll X = min(a[l].first, (total - k * a[r].first) / k);
        if (X) {
            res.push_back({X});
            for (int i = l; i < l + k; i++) {
                a[i].first -= X;
                total -= X;
                res.back().push_back(a[i].second);
            }
            for (int i = r + 1; i < n; i++) {
                a[i].first -= X;
                res.back().push_back(a[i].second);
            }
        }
        if (a[r].first == total / k) {
            total -= a[r].first;
            r--, 
            k--;
        }
        while (l <= r && !a[l].first) l++;
    }
    if (a[n - 1].first) {
        res.push_back({a[n - 1].first});
        while (n && a[n - 1].first)
            res.back().push_back(a[--n].second);
    }
    cout << (int)res.size() << '\n';
    for (auto v : res) {
        for (int c : v) cout << c << ' ';
        cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Correct 1 ms 348 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 1 ms 460 KB n=11
11 Correct 13 ms 3856 KB n=50000
12 Correct 12 ms 3344 KB n=50000
13 Correct 0 ms 344 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 1 ms 348 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Correct 1 ms 348 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 1 ms 460 KB n=11
11 Correct 13 ms 3856 KB n=50000
12 Correct 12 ms 3344 KB n=50000
13 Correct 0 ms 344 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 1 ms 348 KB n=973
17 Correct 1 ms 348 KB n=989
18 Correct 1 ms 344 KB n=563
19 Correct 1 ms 604 KB n=592
20 Correct 1 ms 604 KB n=938
21 Correct 1 ms 604 KB n=747
22 Correct 1 ms 604 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 231 ms 64224 KB Added number should be positive
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 1 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 348 KB n=4
5 Correct 0 ms 348 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 0 ms 348 KB n=5
8 Correct 1 ms 348 KB n=8
9 Correct 0 ms 348 KB n=14
10 Correct 1 ms 460 KB n=11
11 Correct 13 ms 3856 KB n=50000
12 Correct 12 ms 3344 KB n=50000
13 Correct 0 ms 344 KB n=10
14 Correct 1 ms 348 KB n=685
15 Correct 1 ms 348 KB n=623
16 Correct 1 ms 348 KB n=973
17 Correct 1 ms 348 KB n=989
18 Correct 1 ms 344 KB n=563
19 Correct 1 ms 604 KB n=592
20 Correct 1 ms 604 KB n=938
21 Correct 1 ms 604 KB n=747
22 Correct 1 ms 604 KB n=991
23 Incorrect 231 ms 64224 KB Added number should be positive
24 Halted 0 ms 0 KB -