답안 #172906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172906 2020-01-02T17:56:12 Z elitewantsyou Gift (IZhO18_nicegift) C++14
100 / 100
1165 ms 88452 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 = 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.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:71:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i = 0; i < qu.size(); i++){
                        ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 1 ms 380 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 28 ms 3824 KB n=50000
12 Correct 25 ms 3568 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 2 ms 376 KB n=685
15 Correct 2 ms 380 KB n=623
16 Correct 2 ms 376 KB n=973
# 결과 실행 시간 메모리 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 1 ms 380 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 28 ms 3824 KB n=50000
12 Correct 25 ms 3568 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 2 ms 376 KB n=685
15 Correct 2 ms 380 KB n=623
16 Correct 2 ms 376 KB n=973
17 Correct 2 ms 376 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 1 ms 376 KB n=592
20 Correct 2 ms 376 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 2 ms 376 KB n=991
# 결과 실행 시간 메모리 Grader output
1 Correct 654 ms 69348 KB n=1000000
2 Correct 396 ms 38208 KB n=666666
3 Correct 220 ms 19764 KB n=400000
4 Correct 154 ms 13012 KB n=285714
5 Correct 11 ms 1144 KB n=20000
6 Correct 94 ms 8016 KB n=181818
7 Correct 7 ms 888 KB n=10000
8 Correct 6 ms 652 KB n=6666
9 Correct 2 ms 504 KB n=4000
10 Correct 6 ms 504 KB n=2857
11 Correct 3 ms 504 KB n=2000
# 결과 실행 시간 메모리 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 1 ms 380 KB n=14
10 Correct 2 ms 376 KB n=11
11 Correct 28 ms 3824 KB n=50000
12 Correct 25 ms 3568 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 2 ms 376 KB n=685
15 Correct 2 ms 380 KB n=623
16 Correct 2 ms 376 KB n=973
17 Correct 2 ms 376 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 1 ms 376 KB n=592
20 Correct 2 ms 376 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 2 ms 376 KB n=991
23 Correct 654 ms 69348 KB n=1000000
24 Correct 396 ms 38208 KB n=666666
25 Correct 220 ms 19764 KB n=400000
26 Correct 154 ms 13012 KB n=285714
27 Correct 11 ms 1144 KB n=20000
28 Correct 94 ms 8016 KB n=181818
29 Correct 7 ms 888 KB n=10000
30 Correct 6 ms 652 KB n=6666
31 Correct 2 ms 504 KB n=4000
32 Correct 6 ms 504 KB n=2857
33 Correct 3 ms 504 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 51 ms 4940 KB n=100000
39 Correct 57 ms 4968 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 725 ms 85372 KB n=1000000
44 Correct 1165 ms 88452 KB n=1000000
45 Correct 768 ms 61420 KB n=666666
46 Correct 431 ms 33056 KB n=400000
47 Correct 13 ms 888 KB n=2336
48 Correct 728 ms 48852 KB n=285714
49 Correct 621 ms 38016 KB n=181818
50 Correct 37 ms 2696 KB n=40000
51 Correct 18 ms 1524 KB n=20000
52 Correct 11 ms 1016 KB n=10000
53 Correct 62 ms 3320 KB n=6666
54 Correct 8 ms 632 KB n=4000
55 Correct 242 ms 11256 KB n=2857
56 Correct 6 ms 632 KB n=2000