Submission #608807

# Submission time Handle Problem Language Result Execution time Memory
608807 2022-07-27T10:20:19 Z pakhomovee Gift (IZhO18_nicegift) C++17
30 / 100
370 ms 78616 KB
#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
#include <set>
#include <numeric>
#include <queue>

using namespace std;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int& i : a) cin >> i;
    vector<int> b(n, 0);
    priority_queue<pair<int, int>> q;
    vector<pair<int, vector<int>>> act;
    for (int i = 0; i < n; ++i) q.push({ a[i], i });
    while (q.size() >= k) {
        vector<int> pos;
        int delta;
        for (int j = 0; j < k; ++j) {
            pos.push_back(q.top().second);
            delta = q.top().first;
            q.pop();
        }
        if (!q.empty()) {
            delta -= q.top().first - 1;
        }
        for (int i : pos) {
            b[i] += delta;
            if (b[i] < a[i]) {
                q.push({ a[i] - b[i], i });
            }
        }
        act.push_back({ delta, pos });
    }
    if (q.empty()) {
        cout << act.size() << '\n';
        for (pair<int, vector<int>> x : act) {
            cout << x.first << ' ';
            for (int j : x.second) {
                cout << j + 1 << ' ';
            }
            cout << '\n';
        }
    } else {
        cout << -1;
    }
}

Compilation message

nicegift.cpp: In function 'int32_t main()':
nicegift.cpp:23:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |     while (q.size() >= k) {
      |            ~~~~~~~~~^~~~
nicegift.cpp:32:19: warning: 'delta' may be used uninitialized in this function [-Wmaybe-uninitialized]
   32 |             delta -= q.top().first - 1;
      |             ~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 340 KB n=8
9 Correct 6 ms 1108 KB n=14
10 Correct 3 ms 724 KB n=11
11 Correct 27 ms 3648 KB n=50000
12 Correct 29 ms 4228 KB n=50000
13 Correct 12 ms 1996 KB n=10
14 Correct 23 ms 3324 KB n=685
15 Correct 24 ms 3628 KB n=623
16 Correct 14 ms 2108 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 340 KB n=8
9 Correct 6 ms 1108 KB n=14
10 Correct 3 ms 724 KB n=11
11 Correct 27 ms 3648 KB n=50000
12 Correct 29 ms 4228 KB n=50000
13 Correct 12 ms 1996 KB n=10
14 Correct 23 ms 3324 KB n=685
15 Correct 24 ms 3628 KB n=623
16 Correct 14 ms 2108 KB n=973
17 Correct 25 ms 2768 KB n=989
18 Correct 13 ms 952 KB n=563
19 Correct 20 ms 1236 KB n=592
20 Correct 28 ms 1352 KB n=938
21 Correct 13 ms 1160 KB n=747
22 Correct 15 ms 1152 KB n=991
# Verdict Execution time Memory Grader output
1 Incorrect 370 ms 78616 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Correct 1 ms 212 KB n=3
3 Correct 0 ms 212 KB n=3
4 Correct 0 ms 212 KB n=4
5 Correct 0 ms 212 KB n=4
6 Correct 0 ms 212 KB n=2
7 Correct 0 ms 212 KB n=5
8 Correct 1 ms 340 KB n=8
9 Correct 6 ms 1108 KB n=14
10 Correct 3 ms 724 KB n=11
11 Correct 27 ms 3648 KB n=50000
12 Correct 29 ms 4228 KB n=50000
13 Correct 12 ms 1996 KB n=10
14 Correct 23 ms 3324 KB n=685
15 Correct 24 ms 3628 KB n=623
16 Correct 14 ms 2108 KB n=973
17 Correct 25 ms 2768 KB n=989
18 Correct 13 ms 952 KB n=563
19 Correct 20 ms 1236 KB n=592
20 Correct 28 ms 1352 KB n=938
21 Correct 13 ms 1160 KB n=747
22 Correct 15 ms 1152 KB n=991
23 Incorrect 370 ms 78616 KB Jury has the answer but participant has not
24 Halted 0 ms 0 KB -