Submission #608806

# Submission time Handle Problem Language Result Execution time Memory
608806 2022-07-27T10:19:41 Z pakhomovee Gift (IZhO18_nicegift) C++17
0 / 100
1201 ms 524288 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;
        }
        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;
      |             ~~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1201 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1201 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1201 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 423 ms 78548 KB Jury has the answer but participant has not
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1201 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -