Submission #957102

# Submission time Handle Problem Language Result Execution time Memory
957102 2024-04-03T02:06:51 Z Darren0724 Gift (IZhO18_nicegift) C++17
7 / 100
935 ms 66512 KB
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
//#define endl '\n'
const int N=200005;
const int INF=1e18;
const int mod=1e9+7;

int32_t main() {
    LCBorz;
    int n,k;cin>>n>>k;
    vector<int> v(n+1);
    priority_queue<pair<int,int>> pq;
    int total=0;
    for(int i=1;i<=n;i++){
        cin>>v[i];
        pq.push({v[i],i});
        total+=v[i];
    }
    vector<vector<int>> ans;
    while(pq.size()>=k){
        int mn=0;
        vector<int> t;
        for(int i=0;i<k;i++){
            auto [a,b]=pq.top();
            pq.pop();
            mn=a;
            t.push_back(b);
        }
        int mx=(pq.size()?pq.top().first:0);
        int left=total-mx;
        int cost=min(mn,(left-(k-1)*mx)/k);
        for(int j:t){
            v[j]-=cost;
            if(v[j]>0)pq.push({v[j],j});
        }
        left-=cost*k;
        t.push_back(cost);
        reverse(all(t));
        ans.push_back(t);
    }
    if(pq.size()!=0){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans.size()<<endl;
    for(auto v:ans){
        for(int j:v){
            cout<<j<<' ';
        }
        cout<<endl;
    }

    
    return 0;
}

Compilation message

nicegift.cpp: In function 'int32_t main()':
nicegift.cpp:23:20: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   23 |     while(pq.size()>=k){
      |           ~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 600 KB n=4
5 Correct 0 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 600 KB n=4
5 Correct 0 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 600 KB n=5
8 Correct 0 ms 348 KB n=8
9 Incorrect 0 ms 348 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 600 KB n=4
5 Correct 0 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 600 KB n=5
8 Correct 0 ms 348 KB n=8
9 Incorrect 0 ms 348 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 935 ms 66512 KB n=1000000
2 Correct 535 ms 40744 KB n=666666
3 Correct 284 ms 22200 KB n=400000
4 Incorrect 69 ms 12744 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB n=4
2 Correct 0 ms 348 KB n=3
3 Correct 0 ms 348 KB n=3
4 Correct 0 ms 600 KB n=4
5 Correct 0 ms 344 KB n=4
6 Correct 0 ms 348 KB n=2
7 Correct 1 ms 600 KB n=5
8 Correct 0 ms 348 KB n=8
9 Incorrect 0 ms 348 KB Jury has the answer but participant has not
10 Halted 0 ms 0 KB -