Submission #1163505

#TimeUsernameProblemLanguageResultExecution timeMemory
1163505YSH2020Akcija (COCI21_akcija)C++20
50 / 110
91 ms8620 KiB
#include <bits/stdc++.h> using namespace std; #define int long long pair<int, long long> solve(vector<pair<int, int>> a, int d) { priority_queue<int> taken; long long ans = 0; for (int i = 0; i < (int)a.size(); i++) { if (i == d) continue; //case 1: if ((int)taken.size() < a[i].first) { taken.push(a[i].second); ans += a[i].second; } else { //consider to throw away or not if (a[i].second < taken.top()) { ans -= taken.top(); taken.pop(); ans += a[i].second; taken.push(a[i].second); } } } return {(int) taken.size(), ans} ; } bool comp(pair<int, int> x, pair<int, int> y) { if (x.first != y.first) return x.first > y.first; return x.second < y.second; }; signed main() { int n; cin >> n; int k; cin >> k; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) cin >> a[i].second >> a[i].first; sort(a.begin(), a.end()); if (n < 20) { vector<pair<int, int>> poss; for (int i = 0; i < (1<<n); i++) { int total1 = 0, total2 = 0; int possible = 1; for (int j = 0; j < n; j++) { if ((i&(1<<j)) > 0) { total1 += 1; total2 += a[j].second; if (total1 > a[j].first) { possible = 0; break; } } } if (possible == 1) poss.push_back({total1, total2}); } sort(poss.begin(), poss.end(), comp); int c = 1; cout << poss[0].first << ' ' << poss[0].second << '\n'; int idx = 1; while (c < k) { if (poss[idx] != poss[idx-1]) { cout << poss[idx].first << ' ' << poss[idx].second << '\n'; c++; } idx++; } return 0; } pair<int, long long> ans = solve(a, -1); cout << ans.first << ' ' << ans.second << '\n'; if (k > 1) { vector<pair<int, int>> tmp(n); for (int i = 0; i < n; i++) { tmp[i] = solve(a, i); } sort(tmp.begin(), tmp.end(), comp); for (int i = 0; i < n; i++) { if (tmp[i] != ans) { cout << tmp[i].first << ' ' << tmp[i].second << '\n'; return 0; } } } }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...