Submission #93897

# Submission time Handle Problem Language Result Execution time Memory
93897 2019-01-12T22:12:38 Z dalgerok Gift (IZhO18_nicegift) C++14
0 / 100
440 ms 75644 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(sum, 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 2 ms 376 KB n=3
3 Correct 2 ms 376 KB n=3
4 Incorrect 1 ms 376 KB Taken too much stones from the heap
5 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 376 KB Taken too much stones from the heap
5 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 376 KB Taken too much stones from the heap
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 440 ms 75644 KB Taken too much stones from the heap
2 Halted 0 ms 0 KB -
# 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 Incorrect 1 ms 376 KB Taken too much stones from the heap
5 Halted 0 ms 0 KB -