Cod sursa(job #501707)

Utilizator The_DisturbedBungiu Alexandru The_Disturbed Data 16 noiembrie 2010 10:15:20
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<stdio.h>
#include<algorithm>
#define d first
#define l second
#define mh make_heap

using namespace std;

pair <int,int> p[100000];
int n,l,x,max,i,j,tot;

bool cmp(pair<int,int> x,pair<int,int> y)
{
	if(x.l>y.l)return 1;
	if(x.l==y.l&&x.d>y.d)return 1;
	return 0;
}

int main()
{
	freopen("lupul.in","r",stdin);
	freopen("lupul.out","w",stdout);
	scanf("%d%d%d",&n,&x,&l);
	for(i=0;i<n;i++) scanf("%d%d",&p[i].d,&p[i].l);
	sort(p,p+n,cmp);
	tot=0;i=0;
	while(x>=0)
	{
		while(p[i].d>x)i++;
		tot+=p[i].l;
		i++;
		x-=l;
	}
	printf("%d\n",tot);
	return 0;
}