poj supermaket (贪心)

时间:2023-03-09 15:41:46
poj   supermaket  (贪心)

http://poj.org/problem?id=1456

#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct nod
{
int a;
int d; };
bool cmp(nod x,nod y)
{
return x.a>y.a;
}
int main()
{
nod aa[];
int n;
while(cin>>n)
{ int tt[]={};
for(int i=;i<n;i++)
{
cin>>aa[i].a>>aa[i].d;
}
int sum=;
sort(aa,aa+n,cmp);
for(int j=;j<n;j++)
{if(tt[aa[j].d]==)
{
sum+=aa[j].a;
tt[aa[j].d]=;
}
else//////排除比利益较大但天数已经被标记的成员。
{
for(int i=aa[j].d;i>;i--)
{if(tt[i]==)
{ sum+=aa[j].a;
tt[i]=;
break;
}
}
}
}
cout<<sum<<endl; }
return ;
}