Submission #879018

# Submission time Handle Problem Language Result Execution time Memory
879018 2023-11-26T06:32:04 Z The_Samurai Gift (IZhO18_nicegift) C++17
0 / 100
362 ms 73268 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;
    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 + 1);
            pq.pop();
        }
        for (auto [x, i]: v) {
            x = -x;
            if (x > 1) pq.emplace(-(x - 1), i);
        }
        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';
    }

}

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:14:22: 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]
   14 |     while (pq.size() >= k) {
      |            ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Incorrect 0 ms 348 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Incorrect 0 ms 348 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Incorrect 0 ms 348 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 362 ms 73268 KB Not all heaps are empty in the end
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Incorrect 0 ms 348 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -