思路
先按照容纳量排序,挨个判断,如果当前人数无法接受,就删除能力最小的那个
补充
代码
//tokitsukaze and Soldie
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define ll long long
ll const N = 1e5 + 5;
using namespace std;
ll n, v[N], s[N];
priority_queue<ll, vector<ll>, greater<ll> > q;
struct T {
int v, s;
}k[N];
bool cmp(T a, T b) {
return a.s > b.s;
};
int main()
{
scanf("%d", &n);
for (int i = 1; i <= n; ++i)scanf("%d%d", &k[i].v, &k[i].s);
sort(k + 1, k + 1 + n, cmp);
ll z = 0, ans = 0;
for (int i = 1; i <= n; ++i)
{
z += k[i].v;
q.push(k[i].v);
while (q.size() > k[i].s)
{
z -= q.top();
q.pop();
}
ans = max(ans, z);
}
cout << ans << endl;
return 0;
}