답안 #879023

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
879023 2023-11-26T06:37:14 Z The_Samurai Gift (IZhO18_nicegift) C++17
7 / 100
414 ms 64436 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;
    ll sum = accumulate(a.begin(), a.end(), 0ll);
    priority_queue<pair<ll, int>> pq;
    for (int i = 0; i < n; i++) pq.emplace(a[i], i);
    vector<vector<ll>> ans;
    while (pq.size() >= k) {
        vector<pair<ll, int>> v;
        vector<ll> add = {0};
        ll mn = (sum - pq.top().first) / (k - 1);
        for (int i = 0; i < k; i++) {
            v.emplace_back(pq.top());
            mn = min(mn, (ll) v.back().first);
            add.emplace_back(v.back().second + 1);
            pq.pop();
        }
        add[0] = mn;
        sum -= mn * k;
        for (auto [x, i]: v) {
            if (x - mn > 0) pq.emplace(x - mn, 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:15: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]
   15 |     while (pq.size() >= k) {
      |            ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 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 0 ms 348 KB n=8
9 Incorrect 1 ms 348 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 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 0 ms 348 KB n=8
9 Incorrect 1 ms 348 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 414 ms 64436 KB Added number should be positive
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 1 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 0 ms 348 KB n=8
9 Incorrect 1 ms 348 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -