Submission #767718

# Submission time Handle Problem Language Result Execution time Memory
767718 2023-06-27T05:46:27 Z Trunkty Gift (IZhO18_nicegift) C++14
0 / 100
837 ms 112980 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll

int n,k,tot;
int arr[1000005];
map<int,vector<int>> vals;
multiset<int> s;
vector<vector<int>> ans;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        cin >> arr[i];
        s.insert(arr[i]);
        vals[arr[i]].push_back(i);
        tot += arr[i];
    }
    if(tot%k!=0 or tot/k<(*prev(s.end()))){
        cout << -1 << "\n";
        return 0;
    }
    int lef=tot/k;
    s.insert(0);
    while((*prev(s.end()))>0){
        vector<int> v;
        auto it = s.end();
        for(int i=1;i<=k;i++){
            it--;
            v.push_back((*it));
        }
        for(int i:v){
            s.erase(s.find(i));
        }
        int torem = min(v.back(),lef-(*prev(s.end())));
        lef -= torem;
        vector<int> ps={torem};
        for(int i:v){
            int x = vals[i].back();
            vals[i].pop_back();
            ps.push_back(x);
            vals[i-torem].push_back(x);
            s.insert(i-torem);
        }
        ans.push_back(ps);
    }
    cout << ans.size() << "\n";
    for(vector<int> i:ans){
        for(int j:i){
            cout << j << " ";
        }
        cout << "\n";
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Incorrect 1 ms 212 KB Same heap occurs twice
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Incorrect 1 ms 212 KB Same heap occurs twice
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Incorrect 1 ms 212 KB Same heap occurs twice
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 837 ms 112980 KB n=1000000
2 Correct 477 ms 75256 KB n=666666
3 Correct 265 ms 41984 KB n=400000
4 Incorrect 190 ms 30056 KB Same heap occurs twice
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB n=4
2 Incorrect 1 ms 212 KB Same heap occurs twice
3 Halted 0 ms 0 KB -