Submission #721032

#TimeUsernameProblemLanguageResultExecution timeMemory
721032cig32Gift (IZhO18_nicegift)C++17
7 / 100
2067 ms152824 KiB
#pragma GCC optimize("Ofast") #include "bits/stdc++.h" #define int long long using namespace std; const int MAXN = 1e5 + 10; void solve(int tc) { int n, k; cin >> n >> k; priority_queue<pair<int,int> > pq; multiset<int> ms; int a[n+1]; for(int i=1; i<=n; i++) { cin >> a[i]; pq.push({a[i], i}); ms.insert(a[i]); } if(k == n) { for(int i=1; i<n; i++){ if(a[i] != a[i+1]) { cout << "-1\n"; return; } } cout << "1\n"; cout << a[1]; for(int i=1; i<=n; i++) cout << " " << i; cout << '\n'; return; } int lim = 3000000 / k; vector<vector<int> > ops; while(lim--) { while(pq.size() && pq.top().first == 0) pq.pop(); if(pq.empty()) break; if(pq.size() < k) { cout << "-1\n"; return; } int mn = 1e18; stack<pair<int, int> > st; vector<int> lol; for(int i=0; i<k; i++) { st.push(pq.top()); mn = min(mn, pq.top().first); lol.push_back(pq.top().second); pq.pop(); } int cmp = 0; if(ms.size()) cmp = *ms.begin(); mn = max(1ll, mn - cmp); while(st.size()) { if(st.top().first != mn) { pq.push({st.top().first - mn, st.top().second}); } st.pop(); } for(int x: lol) { ms.erase(ms.lower_bound(a[x])); a[x] -= mn; if(a[x] > 0) ms.insert(a[x]); } lol.push_back(mn); ops.push_back(lol); } for(int i=1; i<=n; i++) { if(a[i] != 0) { cout << "-1\n"; return; } } cout << ops.size() << "\n"; for(vector<int> v: ops) { cout << v.back(); for(int i=0; i<k; i++) cout << " " << v[i]; cout << "\n"; } } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); int t=1; //cin>>t; for(int i=1; i<=t; i++)solve(i); } /* 5 2 1 2 4 8 15 3 2 1 2 3 5 3 6 6 4 2 0 4 2 2 3 3 2 */

Compilation message (stderr)

nicegift.cpp: In function 'void solve(long long int)':
nicegift.cpp:34:18: 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]
   34 |     if(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...