1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| #include <bits/stdc++.h>
using namespace std;
int main() { int n, v, s, k; long ans = 0, sum = 0; cin >> n; vector<pair<int, int>> solders(n); for (int i = 0; i < n; i++) { cin >> v >> s; solders[i] = {s, v}; } sort(solders.begin(), solders.end()); priority_queue<int, vector<int>, greater<int>> q; for (int i = n - 1; i >= 0; --i) { auto[s, v] = solders[i]; q.push(v); sum += v; k = s; while (q.size() > k) { sum -= q.top(); q.pop(); } ans = max(ans, sum); } cout << ans << endl; return 0; }
|