Submission #878278

# Submission time Handle Problem Language Result Execution time Memory
878278 2023-11-24T07:55:40 Z The_Samurai Gift (IZhO18_nicegift) C++17
0 / 100
106 ms 18812 KB
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int inf = 1e9;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll &x: a) cin >> x;
    if (accumulate(a.begin(), a.end(), 0ll) <= 1e5) {
        priority_queue<pair<ll, int>> pq;
        for (int i = 0; i < n; i++) pq.emplace(a[i], i);
        vector<vector<int>> ans;
        while (pq.size() >= k) {
            vector<pair<int, int>> v;
            vector<int> add = {1};
            for (int i = 0; i < k; i++) {
                v.emplace_back(pq.top());
                add.emplace_back(v.back().second);
                pq.pop();
            }
            for (auto [x, i]: v) {
                if (x > 1) pq.emplace(x - 1, i + 1);
            }
            ans.emplace_back(add);
        }
        if (!pq.empty()) {
            cout << -1;
            return;
        }
        cout << ans.size() << '\n';
        for (auto v: ans) {
            for (int x: v) cout << x << ' ';
            cout << '\n';
        }
        return;
    }
}

int main() {
    cin.tie(0)->sync_with_stdio(false);
#ifdef sunnatov
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int queries = 1;
//    cin >> queries;

    for (int test_case = 1; test_case <= queries; test_case++) {
#ifdef sunnatov
        cout << "Test case: " << test_case << endl;
#endif
        solve();
        cout << '\n';
    }
}

Compilation message

nicegift.cpp: In function 'void solve()':
nicegift.cpp:15:26: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   15 |         while (pq.size() >= k) {
      |                ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Same heap occurs twice
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Same heap occurs twice
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Same heap occurs twice
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 106 ms 18812 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Same heap occurs twice
2 Halted 0 ms 0 KB -