Cod sursa(job #808220)

Utilizator raulstoinStoin Raul raulstoin Data 6 noiembrie 2012 15:16:55
Problema Lupul Urias si Rau Scor 16
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<cstdio>
#include<algorithm>
#include <utility>
#define INF 2147483647
#define dist first
#define profit second
using namespace std;
pair <int,int> oaie[100000];
int n,x,l,s;
int main()
{
	freopen("lupu.in","r",stdin);
	freopen("lupu.out","w",stdout);
	scanf("%d %d %d",&n,&x,&l);
	int i,k,s=0;
	for(i=1;i<=n;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		oaie[i].dist=(x-a)/l+1;
		oaie[i].profit=b;
	}
	sort(oaie+1,oaie+n+1);
	reverse(oaie+1,oaie+n+1);
	k=oaie[1].dist;
	i=1;
	while(k)
	{
		while(i<=n && k!=oaie[i].dist)
			i++;
		if(i<=n && k==oaie[i].dist)
		{
			s+=oaie[i].profit;
			i++;
		}
		k--;
	}
	printf("%d\n",s);
	return 0;
}