小贪心,暴力过得,我自己都没想到……还以为要用并查集优化呢
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 10010
struct data
{
int d, v;
}a[N];
bool f[N];
int cmp(data a, data b)
{
return a.v > b.v;
}
int main()
{
int n, i, mv;
while (scanf("%d", &n) != EOF)
{
mv = 0;
memset(f, 0, sizeof(f));
for (i = 0; i < n; i++)
scanf("%d%d", &a[i].v, &a[i].d);
sort(a, a + n, cmp);
for (i = 0; i < n; i++)
{
int t = a[i].d;
while (t > 0 && f[t]) t--;
if (t > 0)
{
f[t] = 1;
mv += a[i].v;
}
}
printf("%d\n", mv);
}
return 0;
}