Submission #1060524

# Submission time Handle Problem Language Result Execution time Memory
1060524 2024-08-15T16:44:11 Z Jarif_Rahman Gift (IZhO18_nicegift) C++17
100 / 100
585 ms 102328 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, k; cin >> n >> k;
    vector<ll> A(n);
    for(ll &x: A) cin >> x;
    vector<pair<ll, vector<int>>> ans;

    priority_queue<pair<ll, int>> pq;
    for(int i = 0; i < n; i++) pq.push({A[i], i});

    ll X = 0;
    for(ll x: A) X+=x;
    if(X%k != 0 || *max_element(A.begin(), A.end()) > X/k){
        cout << "-1\n";
        exit(0);
    }
    X/=k;

    while(pq.size() >= k){
        vector<int> cur;
        for(int i = 0; i < k; i++) cur.push_back(pq.top().second), pq.pop();
        ll lim = 0;
        if(!pq.empty()) lim = pq.top().first;
        ll d = X-lim;
        for(int x: cur) d = min(d, A[x]);
        for(int x: cur) A[x]-=d;
        ans.push_back({d, cur});
        X-=d;
        for(int x: cur) if(A[x]) pq.push({A[x], x});
    }

    if(pq.size() != 0){
        cout << "-1\n";
        exit(0);
    }
    cout << ans.size() << "\n";
    for(auto [x, v]: ans){
        cout << x << " ";
        for(int i: v) cout << i+1 << " ";
        cout << "\n";
    }
}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:24:21: 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]
   24 |     while(pq.size() >= k){
      |           ~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 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 1 ms 348 KB n=5
8 Correct 0 ms 348 KB n=8
9 Correct 1 ms 348 KB n=14
10 Correct 1 ms 344 KB n=11
11 Correct 15 ms 4052 KB n=50000
12 Correct 15 ms 3796 KB n=50000
13 Correct 0 ms 348 KB n=10
14 Correct 0 ms 348 KB n=685
15 Correct 0 ms 348 KB n=623
16 Correct 1 ms 600 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 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 1 ms 348 KB n=5
8 Correct 0 ms 348 KB n=8
9 Correct 1 ms 348 KB n=14
10 Correct 1 ms 344 KB n=11
11 Correct 15 ms 4052 KB n=50000
12 Correct 15 ms 3796 KB n=50000
13 Correct 0 ms 348 KB n=10
14 Correct 0 ms 348 KB n=685
15 Correct 0 ms 348 KB n=623
16 Correct 1 ms 600 KB n=973
17 Correct 1 ms 348 KB n=989
18 Correct 0 ms 348 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 348 KB n=938
21 Correct 0 ms 348 KB n=747
22 Correct 1 ms 492 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 313 ms 70456 KB n=1000000
2 Correct 203 ms 46260 KB n=666666
3 Correct 129 ms 25244 KB n=400000
4 Correct 78 ms 17256 KB n=285714
5 Correct 5 ms 1504 KB n=20000
6 Correct 54 ms 10692 KB n=181818
7 Correct 3 ms 984 KB n=10000
8 Correct 4 ms 1116 KB n=6666
9 Correct 1 ms 604 KB n=4000
10 Correct 3 ms 604 KB n=2857
11 Correct 1 ms 348 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 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 1 ms 348 KB n=5
8 Correct 0 ms 348 KB n=8
9 Correct 1 ms 348 KB n=14
10 Correct 1 ms 344 KB n=11
11 Correct 15 ms 4052 KB n=50000
12 Correct 15 ms 3796 KB n=50000
13 Correct 0 ms 348 KB n=10
14 Correct 0 ms 348 KB n=685
15 Correct 0 ms 348 KB n=623
16 Correct 1 ms 600 KB n=973
17 Correct 1 ms 348 KB n=989
18 Correct 0 ms 348 KB n=563
19 Correct 1 ms 348 KB n=592
20 Correct 1 ms 348 KB n=938
21 Correct 0 ms 348 KB n=747
22 Correct 1 ms 492 KB n=991
23 Correct 313 ms 70456 KB n=1000000
24 Correct 203 ms 46260 KB n=666666
25 Correct 129 ms 25244 KB n=400000
26 Correct 78 ms 17256 KB n=285714
27 Correct 5 ms 1504 KB n=20000
28 Correct 54 ms 10692 KB n=181818
29 Correct 3 ms 984 KB n=10000
30 Correct 4 ms 1116 KB n=6666
31 Correct 1 ms 604 KB n=4000
32 Correct 3 ms 604 KB n=2857
33 Correct 1 ms 348 KB n=2000
34 Correct 10 ms 2780 KB n=23514
35 Correct 11 ms 2524 KB n=23514
36 Correct 1 ms 348 KB n=940
37 Correct 0 ms 348 KB n=2
38 Correct 29 ms 5480 KB n=100000
39 Correct 29 ms 5324 KB n=100000
40 Correct 0 ms 348 KB n=10
41 Correct 0 ms 388 KB n=100
42 Correct 2 ms 604 KB n=1000
43 Correct 396 ms 92692 KB n=1000000
44 Correct 585 ms 102328 KB n=1000000
45 Correct 385 ms 65972 KB n=666666
46 Correct 227 ms 35004 KB n=400000
47 Correct 7 ms 860 KB n=2336
48 Correct 401 ms 49076 KB n=285714
49 Correct 354 ms 40636 KB n=181818
50 Correct 19 ms 2768 KB n=40000
51 Correct 9 ms 1504 KB n=20000
52 Correct 6 ms 984 KB n=10000
53 Correct 36 ms 3356 KB n=6666
54 Correct 3 ms 604 KB n=4000
55 Correct 143 ms 11348 KB n=2857
56 Correct 2 ms 604 KB n=2000