제출 #881306

#제출 시각아이디문제언어결과실행 시간메모리
881306dimashhhGift (IZhO18_nicegift)C++17
30 / 100
567 ms177684 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 1;
ll n,k;
ll a[N];
set<pair<ll,ll>> st;
vector<pair<vector<int>,int>> res(N * 3);
ll s =0;
void test(){
    cin >> n >> k;
    for(int i = 1;i <= n;i++){
        cin >> a[i];
        st.insert({a[i],i});
        s += a[i];
    }
    if(s % k || (*st.rbegin()).first > s / k){
        cout << -1;
        return;
    }
    int it = 1;    
    while(!st.empty()){
        vector<int> f;
        ll oo;
        for(int i = 1;i <= k;i++){
            auto [x,y] = *st.rbegin();
            st.erase({x,y});
            oo = x;
            f.push_back(y);
        }
        if(st.size()){
            ll val = (*st.rbegin()).first;
            oo = min(oo,(-val * k + s) / k);
        }
        s -= k * oo;
        res[it] = {f,oo};
        it++;
        for(auto j:f){
            a[j] -= oo;
            if(a[j]){
                st.insert({a[j],j});
            }
        }
    }
    cout << it - 1 << '\n';
    for(int f = 1;f < it;f++){
        cout << res[f].second << ' ';
        for(auto j:res[f].first)
            cout << j << ' ';
        cout << '\n';
    }
}
main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int T = 1;
    // cin >> T;
    while(T--)
        test();
}

컴파일 시 표준 에러 (stderr) 메시지

nicegift.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | main(){
      | ^~~~
nicegift.cpp: In function 'void test()':
nicegift.cpp:24:12: warning: 'oo' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |         ll oo;
      |            ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...