链接:
http://poj.org/problem?id=1456
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82830#problem/G
代码:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
using namespace std;
#define N 11000
#define INF 0xfffffff
struct node
{
int a,b;
}p[N];
int cmp(node a, node b)
{
return a.a > b.a;
}
int main()
{
int n,i,j,vis[N];
while(scanf("%d",&n)!=EOF)
{
memset(vis,0,sizeof(vis));
memset(p,0,sizeof(p));
for(i=0;i<n;i++)
scanf("%d %d",&p[i].a,&p[i].b);
sort(p,p+n,cmp);
int sum=0;
for(i=0;i<n;i++)
{
for(j=p[i].b;j>0;j--)
{
if(vis[j]==0)
{
sum=sum+p[i].a;
vis[j]=1;
break;
}
}
}
printf("%d
",sum);
}
return 0;
}