Submission #172903

# Submission time Handle Problem Language Result Execution time Memory
172903 2020-01-02T17:53:20 Z elitewantsyou Gift (IZhO18_nicegift) C++14
49 / 100
2000 ms 122784 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;
        set < pair < long long, int > > s;
        long long S = 0;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
                s.insert({a[i], i});

                S += a[i];
        }
        if(1ll * (--s.end())->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.end())->se);
                        s.erase(--s.end());
                }
                long long rem = 0;
                if(!s.empty()){
                        rem = (--s.end())->fi;
                }
                long long l = 1, dif = a[v[0]] - rem;
                if(rem <= (S - dif * k) / k){
                        l = (S - rem * k) / k;
                        l = min(l, a[v.back()]);
                } else{
                        assert(0);
                }

                S -= k * l;
                res.push_back(v);
                qu.push_back(l);
                for(int i: v){
                        a[i] -= l;
                        if(!a[i]){
                                continue;
                        }
                        s.insert({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:70: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 380 KB n=3
3 Correct 4 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 380 KB n=3
3 Correct 4 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 34 ms 5404 KB n=50000
12 Correct 27 ms 4976 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 2 ms 504 KB n=685
15 Correct 1 ms 420 KB n=623
16 Correct 2 ms 420 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 380 KB n=3
3 Correct 4 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 34 ms 5404 KB n=50000
12 Correct 27 ms 4976 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 2 ms 504 KB n=685
15 Correct 1 ms 420 KB n=623
16 Correct 2 ms 420 KB n=973
17 Correct 2 ms 504 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 3 ms 376 KB n=592
20 Correct 3 ms 504 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 3 ms 376 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 845 ms 84704 KB n=1000000
2 Correct 525 ms 55004 KB n=666666
3 Correct 302 ms 32468 KB n=400000
4 Correct 207 ms 23028 KB n=285714
5 Correct 14 ms 2168 KB n=20000
6 Correct 134 ms 17748 KB n=181818
7 Correct 8 ms 1272 KB n=10000
8 Correct 7 ms 888 KB n=6666
9 Correct 4 ms 760 KB n=4000
10 Correct 7 ms 632 KB n=2857
11 Correct 3 ms 504 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 2 ms 380 KB n=3
3 Correct 4 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 34 ms 5404 KB n=50000
12 Correct 27 ms 4976 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 2 ms 504 KB n=685
15 Correct 1 ms 420 KB n=623
16 Correct 2 ms 420 KB n=973
17 Correct 2 ms 504 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 3 ms 376 KB n=592
20 Correct 3 ms 504 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 3 ms 376 KB n=991
23 Correct 845 ms 84704 KB n=1000000
24 Correct 525 ms 55004 KB n=666666
25 Correct 302 ms 32468 KB n=400000
26 Correct 207 ms 23028 KB n=285714
27 Correct 14 ms 2168 KB n=20000
28 Correct 134 ms 17748 KB n=181818
29 Correct 8 ms 1272 KB n=10000
30 Correct 7 ms 888 KB n=6666
31 Correct 4 ms 760 KB n=4000
32 Correct 7 ms 632 KB n=2857
33 Correct 3 ms 504 KB n=2000
34 Correct 27 ms 3252 KB n=23514
35 Correct 27 ms 3252 KB n=23514
36 Correct 3 ms 508 KB n=940
37 Correct 2 ms 376 KB n=2
38 Correct 75 ms 9392 KB n=100000
39 Correct 76 ms 9420 KB n=100000
40 Correct 2 ms 376 KB n=10
41 Correct 3 ms 376 KB n=100
42 Correct 5 ms 504 KB n=1000
43 Correct 1174 ms 122784 KB n=1000000
44 Execution timed out 2024 ms 90244 KB Time limit exceeded
45 Halted 0 ms 0 KB -