和HDU 1789 - Doing Homework again一个套路
#include<cstdio>
#include<algorithm>
using namespace std;
struct type{
int profit;
int deadline;
}prod[10000+5];
bool day[10000+5];
bool cmp(type x,type y)
{
return x.profit>y.profit;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1;i<=n;i++) scanf("%d %d",&prod[i].profit,&prod[i].deadline);
sort(prod+1,prod+n+1,cmp);
memset(day,0,sizeof(day));
int profit_sum=0;
for(int i=1;i<=n;i++){
for(int j=prod[i].deadline;j>=1;j--)
{
if(day[j] == 0){
day[j]=1;
profit_sum+=prod[i].profit;
break;
}
}
}
printf("%d\n",profit_sum);
}
}
HDU 1789 - Doing Homework again