贪心策略:一定先卖价值最大的,然后考虑卖当前的物品,卖的日期越靠后,越优,可以为以后的物品提供机会
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=1e4+;
struct Node{
int v,d;
bool operator<(const Node &rhs)const{
return v>rhs.v;
}
}p[N];
bool vis[N];
int main()
{
int n;
while(~scanf("%d",&n)){
memset(vis,,sizeof(vis));
for(int i=;i<=n;++i){
scanf("%d%d",&p[i].v,&p[i].d);
}
sort(p+,p++n);
int ans=;
for(int i=;i<=n;++i){
for(int j=p[i].d;j>=;--j)
if(!vis[j]){ans+=p[i].v,vis[j]=;break;}
}
printf("%d\n",ans);
}
return ;
}