Submission #172915

# Submission time Handle Problem Language Result Execution time Memory
172915 2020-01-02T18:09:06 Z elitewantsyou Gift (IZhO18_nicegift) C++14
100 / 100
1171 ms 88756 KB
#include <bits/stdc++.h>

//#pragma GCC optimize("Ofast")

#define fi first
#define se second

const int N = 1000010;

using namespace std;

int n;
int k;
long long a[N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        ios_base::sync_with_stdio(0);

        cin >> n >> k;
        priority_queue < pair < long long, int > > s;
        long long S = 0;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
                s.push({a[i], i});

                S += a[i];
        }

        if(1ll * s.top().fi > S / k || S % k){
                cout << -1 << "\n";
                return 0;
        }

        vector < long long > qu;
        vector < vector < int > > res;
        vector < int > v;
        while(s.size() > 0){
                v.clear();
                for(int i = 0; i < k; i++){
                        v.push_back(s.top().se);
                        s.pop();
                }
                long long rem = 0;
                if(!s.empty()){
                        rem = s.top().fi;
                }
                long long l = (S - rem * k) / k;
                l = min(l, a[v.back()]);

                S -= k * l;
                res.push_back(v);
                qu.push_back(l);
                for(int i: v){
                        a[i] -= l;
                        if(!a[i]){
                                continue;
                        }
                        s.push({a[i], i});
                }
        }
        cout << qu.size() << "\n";
        for(int i = 0; i < qu.size(); i++){
                cout << qu[i];
                for(int x: res[i]){
                        cout << " " << x;
                }
                cout << "\n";
        }

}

Compilation message

nicegift.cpp: In function 'int main()':
nicegift.cpp:66:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < qu.size(); i++){
                        ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 376 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 27 ms 3820 KB n=50000
12 Correct 23 ms 3540 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 3 ms 376 KB n=685
15 Correct 2 ms 376 KB n=623
16 Correct 3 ms 376 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 376 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 27 ms 3820 KB n=50000
12 Correct 23 ms 3540 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 3 ms 376 KB n=685
15 Correct 2 ms 376 KB n=623
16 Correct 3 ms 376 KB n=973
17 Correct 2 ms 376 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 2 ms 376 KB n=592
20 Correct 2 ms 376 KB n=938
21 Correct 2 ms 376 KB n=747
22 Correct 2 ms 376 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 614 ms 69268 KB n=1000000
2 Correct 391 ms 38168 KB n=666666
3 Correct 218 ms 19796 KB n=400000
4 Correct 152 ms 13012 KB n=285714
5 Correct 11 ms 1144 KB n=20000
6 Correct 95 ms 8032 KB n=181818
7 Correct 7 ms 760 KB n=10000
8 Correct 6 ms 652 KB n=6666
9 Correct 4 ms 504 KB n=4000
10 Correct 6 ms 632 KB n=2857
11 Correct 3 ms 376 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Correct 2 ms 376 KB n=4
5 Correct 2 ms 376 KB n=4
6 Correct 2 ms 376 KB n=2
7 Correct 2 ms 376 KB n=5
8 Correct 2 ms 376 KB n=8
9 Correct 2 ms 376 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 27 ms 3820 KB n=50000
12 Correct 23 ms 3540 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 3 ms 376 KB n=685
15 Correct 2 ms 376 KB n=623
16 Correct 3 ms 376 KB n=973
17 Correct 2 ms 376 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 2 ms 376 KB n=592
20 Correct 2 ms 376 KB n=938
21 Correct 2 ms 376 KB n=747
22 Correct 2 ms 376 KB n=991
23 Correct 614 ms 69268 KB n=1000000
24 Correct 391 ms 38168 KB n=666666
25 Correct 218 ms 19796 KB n=400000
26 Correct 152 ms 13012 KB n=285714
27 Correct 11 ms 1144 KB n=20000
28 Correct 95 ms 8032 KB n=181818
29 Correct 7 ms 760 KB n=10000
30 Correct 6 ms 652 KB n=6666
31 Correct 4 ms 504 KB n=4000
32 Correct 6 ms 632 KB n=2857
33 Correct 3 ms 376 KB n=2000
34 Correct 19 ms 2416 KB n=23514
35 Correct 19 ms 2416 KB n=23514
36 Correct 3 ms 504 KB n=940
37 Correct 2 ms 376 KB n=2
38 Correct 50 ms 4844 KB n=100000
39 Correct 53 ms 4980 KB n=100000
40 Correct 2 ms 376 KB n=10
41 Correct 2 ms 376 KB n=100
42 Correct 5 ms 504 KB n=1000
43 Correct 706 ms 85280 KB n=1000000
44 Correct 1171 ms 88756 KB n=1000000
45 Correct 744 ms 52132 KB n=666666
46 Correct 415 ms 27516 KB n=400000
47 Correct 13 ms 888 KB n=2336
48 Correct 705 ms 44864 KB n=285714
49 Correct 602 ms 35540 KB n=181818
50 Correct 34 ms 2160 KB n=40000
51 Correct 17 ms 1264 KB n=20000
52 Correct 11 ms 888 KB n=10000
53 Correct 61 ms 3192 KB n=6666
54 Correct 6 ms 504 KB n=4000
55 Correct 241 ms 11256 KB n=2857
56 Correct 5 ms 504 KB n=2000