Submission #93898

# Submission time Handle Problem Language Result Execution time Memory
93898 2019-01-12T22:14:26 Z dalgerok Gift (IZhO18_nicegift) C++14
100 / 100
708 ms 125008 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;



const int N = 1e6 + 5;



int n, k, a[N], pos[N];


main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> k;
    int sum = 0, mx = 0;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
        mx = max(mx, a[i]);
    }
    if(sum % k){
        return cout << "-1", 0;
    }
    int val = sum / k;
    if(mx > val){
        return cout << "-1", 0;
    }
    sum = 0;
    vector < vector < pair < int, int > > > q;
    vector < pair < int, int > > cur;
    for(int i = 1; i <= n; i++){
        sum += a[i];
        if(sum >= val){
            cur.push_back(make_pair(a[i] - (sum - val), i));
            q.push_back(cur);
            cur.clear();
            sum -= val;
            if(sum > 0){
                cur.push_back(make_pair(sum, i));
            }
        }
        else{
            cur.push_back(make_pair(a[i], i));
        }
    }
    vector < vector < int > > ans;
    while(true){
        int mn = 9e18;
        for(int i = 0; i < k; i++){
            mn = min(mn, q[i][pos[i]].first);
        }
        bool flag = false;
        vector < int > vec;
        vec.push_back(mn);
        for(int i = 0; i < k; i++){
            vec.push_back(q[i][pos[i]].second);
            q[i][pos[i]].first -= mn;
            if(pos[i] < (int)q[i].size() && q[i][pos[i]].first == 0){
                pos[i] += 1;
                if(pos[i] < (int)q[i].size()){
                    flag = true;
                }
            }
        }
        ans.push_back(vec);
        if(flag == false){
            break;
        }
    }
    cout << (int)ans.size() << "\n";
    for(auto it : ans){
        for(auto x : it){
            cout << x << " ";
        }
        cout << "\n";
    }
}


Compilation message

nicegift.cpp:14:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 1 ms 376 KB n=3
3 Correct 1 ms 380 KB n=3
4 Correct 2 ms 508 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 1 ms 376 KB n=3
3 Correct 1 ms 380 KB n=3
4 Correct 2 ms 508 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 5100 KB n=50000
12 Correct 25 ms 4844 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 2 ms 508 KB n=685
15 Correct 2 ms 504 KB n=623
16 Correct 2 ms 376 KB n=973
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 1 ms 376 KB n=3
3 Correct 1 ms 380 KB n=3
4 Correct 2 ms 508 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 5100 KB n=50000
12 Correct 25 ms 4844 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 2 ms 508 KB n=685
15 Correct 2 ms 504 KB n=623
16 Correct 2 ms 376 KB n=973
17 Correct 2 ms 504 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 3 ms 504 KB n=592
20 Correct 3 ms 632 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 3 ms 504 KB n=991
# Verdict Execution time Memory Grader output
1 Correct 447 ms 73116 KB n=1000000
2 Correct 256 ms 52056 KB n=666666
3 Correct 139 ms 27108 KB n=400000
4 Correct 335 ms 57692 KB n=285714
5 Correct 7 ms 1400 KB n=20000
6 Correct 280 ms 46556 KB n=181818
7 Correct 4 ms 888 KB n=10000
8 Correct 30 ms 4856 KB n=6666
9 Correct 3 ms 504 KB n=4000
10 Correct 157 ms 25464 KB n=2857
11 Correct 2 ms 504 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB n=4
2 Correct 1 ms 376 KB n=3
3 Correct 1 ms 380 KB n=3
4 Correct 2 ms 508 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 5100 KB n=50000
12 Correct 25 ms 4844 KB n=50000
13 Correct 2 ms 376 KB n=10
14 Correct 2 ms 508 KB n=685
15 Correct 2 ms 504 KB n=623
16 Correct 2 ms 376 KB n=973
17 Correct 2 ms 504 KB n=989
18 Correct 2 ms 376 KB n=563
19 Correct 3 ms 504 KB n=592
20 Correct 3 ms 632 KB n=938
21 Correct 3 ms 504 KB n=747
22 Correct 3 ms 504 KB n=991
23 Correct 447 ms 73116 KB n=1000000
24 Correct 256 ms 52056 KB n=666666
25 Correct 139 ms 27108 KB n=400000
26 Correct 335 ms 57692 KB n=285714
27 Correct 7 ms 1400 KB n=20000
28 Correct 280 ms 46556 KB n=181818
29 Correct 4 ms 888 KB n=10000
30 Correct 30 ms 4856 KB n=6666
31 Correct 3 ms 504 KB n=4000
32 Correct 157 ms 25464 KB n=2857
33 Correct 2 ms 504 KB n=2000
34 Correct 15 ms 2992 KB n=23514
35 Correct 16 ms 2864 KB n=23514
36 Correct 2 ms 376 KB n=940
37 Correct 2 ms 376 KB n=2
38 Correct 89 ms 15080 KB n=100000
39 Correct 89 ms 15076 KB n=100000
40 Correct 2 ms 376 KB n=10
41 Correct 2 ms 376 KB n=100
42 Correct 6 ms 1016 KB n=1000
43 Correct 641 ms 117800 KB n=1000000
44 Correct 708 ms 125008 KB n=1000000
45 Correct 523 ms 96708 KB n=666666
46 Correct 390 ms 68376 KB n=400000
47 Correct 152 ms 25256 KB n=2336
48 Correct 334 ms 57608 KB n=285714
49 Correct 297 ms 46680 KB n=181818
50 Correct 297 ms 30632 KB n=40000
51 Correct 173 ms 28524 KB n=20000
52 Correct 158 ms 26420 KB n=10000
53 Correct 168 ms 26104 KB n=6666
54 Correct 160 ms 25532 KB n=4000
55 Correct 152 ms 25336 KB n=2857
56 Correct 149 ms 24516 KB n=2000