Pagini recente » Cod sursa (job #560062) | Cod sursa (job #877427) | Cod sursa (job #2755229) | Cod sursa (job #46697) | Cod sursa (job #2062951)
#include<stdio.h>
#include<algorithm>
#define MAXN 100000
struct Sheep
{
int profit;
int turns_survived;
};
bool cmp(Sheep,Sheep);
FILE*fin,*fout;
Sheep sheeps[MAXN+1];
int main()
{
fin=fopen("lupu.in","r");
fout=fopen("lupu.out","w");
int N,X,L;
fscanf(fin,"%d%d%d",&N,&X,&L);
for(int i=1;i<=N;i++)
{
int initial_d,wool;
fscanf(fin,"%d%d",&initial_d,&wool);
sheeps[i].profit=wool;
sheeps[i].turns_survived=(X-initial_d)/L;
if(sheeps[i].turns_survived<0)
{
sheeps[i].turns_survived=0;
}
}
std::sort(&sheeps[1],&sheeps[N+1],cmp);
int ans=sheeps[1].profit;
for(int i=2;i<=N;i++)
{
if(sheeps[i].turns_survived!=sheeps[i-1].turns_survived)
{
ans+=sheeps[i].profit;
}
}
fprintf(fout,"%d",ans);
fclose(fin);
fclose(fout);
return 0;
}
bool cmp(Sheep a,Sheep b)
{
if(a.turns_survived==b.turns_survived)
{
return a.profit>b.profit;
}
return a.turns_survived<b.turns_survived;
}