Submission #1060489

#TimeUsernameProblemLanguageResultExecution timeMemory
1060489Jarif_RahmanGift (IZhO18_nicegift)C++17
30 / 100
841 ms231524 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n, k; cin >> n >> k; vector<ll> A(n); for(ll &x: A) cin >> x; vector<pair<ll, vector<int>>> ans; priority_queue<pair<ll, int>> pq; for(int i = 0; i < n; i++) pq.push({A[i], i}); ll sum = 0; for(ll x: A) sum+=x; if(sum%k != 0 || *max_element(A.begin(), A.end()) > sum/k){ cout << "-1\n"; exit(0); } while(pq.size() >= k){ vector<int> cur; for(int i = 0; i < k; i++) cur.push_back(pq.top().second), pq.pop(); ll lim = 0; if(!pq.empty()) lim = pq.top().first-1; ll mn = 1e18+5; for(int x: cur) mn = min(mn, A[x]-lim); for(int x: cur) A[x]-=mn; ans.push_back({mn, cur}); if(ans.size() > int(3e6)){ cout << "-1\n"; exit(0); } for(int x: cur) if(A[x]) pq.push({A[x], x}); } if(pq.size() != 0){ cout << "-1\n"; exit(0); } cout << ans.size() << "\n"; for(auto [x, v]: ans){ cout << x << " "; for(int i: v) cout << i+1 << " "; cout << "\n"; } }

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:23:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   23 |     while(pq.size() >= k){
      |           ~~~~~~~~~~^~~~
#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...