Submission #171308

#TimeUsernameProblemLanguageResultExecution timeMemory
171308emil_physmathGift (IZhO18_nicegift)C++17
100 / 100
1389 ms102676 KiB
#include <algorithm> #include <iostream> #include <vector> #include <queue> #include <cmath> #include <map> #include <set> using namespace std; typedef double ldouble; typedef long long llong; const int maxN = 100001; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n, k; cin >> n >> k; vector<llong> arr(n); priority_queue<pair<llong, int>> a; llong mx = -1, sum = 0; for (int i = 0; i < n; ++i) { cin >> arr[i]; sum += arr[i]; mx = max(mx, arr[i]); a.push({arr[i], i}); } if (sum % k || mx > sum / k) { cout << -1 << endl; exit(0); } vector<pair<llong, vector<int>>> ans; while (a.top().first) { vector<int> cur; llong mn = a.top().first; while (cur.size() < k) { cur.push_back(a.top().second); mn = min(mn, a.top().first); a.pop(); } if (!a.empty()) mn = min(mn, sum / k - a.top().first); if (!mn) throw; // it->first <= (sum - k * mn) / k // k * it->first <= sum - k * mn // mn * k <= sum - k * it->first // mn <= sum / k - it->first /* mn = min(mn, a.rbegin()->first - it->first + 1); */ /* if (!mn) { cout << -1 << endl; exit(0); } */ for (int x: cur) { // a.erase({arr[x], x}); sum -= arr[x]; a.push({arr[x] -= mn, x}); sum += arr[x]; } ans.push_back({mn, cur}); /*cerr << "a` "; for (pair<llong, int> i: a) cerr << i.first << ' '; cerr << endl;*/ } cout << ans.size() << '\n'; for (auto x: ans) { cout << x.first << ' '; for (int y: x.second) cout << y + 1 << ' '; cout << '\n'; } } // 6 5 4 3 x // x x-1 x-2 x-3 x

Compilation message (stderr)

nicegift.cpp: In function 'int main()':
nicegift.cpp:40:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (cur.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...