Submission #881307

#TimeUsernameProblemLanguageResultExecution timeMemory
881307dimashhhGift (IZhO18_nicegift)C++17
100 / 100
639 ms172940 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 1e6 + 1; #define int long long ll n,k; ll a[N]; priority_queue<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.push({a[i],i}); s += a[i]; } if(s % k || (st.top()).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.top(); st.pop(); oo = x; f.push_back(y); } if(st.size()){ ll val = (st.top()).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.push({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(); }

Compilation message (stderr)

nicegift.cpp:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main(){
      | ^~~~
nicegift.cpp: In function 'void test()':
nicegift.cpp:25:12: warning: 'oo' may be used uninitialized in this function [-Wmaybe-uninitialized]
   25 |         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...