Cod sursa(job #916124)

Utilizator superman_01Avramescu Cristian superman_01 Data 15 martie 2013 20:37:44
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include<fstream>
#include<vector>
#include<utility>
#include<algorithm>
#include<queue>

#define MAX_SIZE 100005

FILE *f=fopen("lupu.in","r");
FILE *g=fopen("lupu.out","w");

using namespace std;

 pair <int,int>  o[MAX_SIZE];
int n,dist,l;
long long RES;

priority_queue <int> bst;
int main()
{
	fscanf(f,"%d%d%d",&n,&dist,&l);
	int a,b;
	for(int i(0); i <n; ++i )
	{
		fscanf(f,"%d%d",&a,&b);
		o[i].first=(dist-a)/l+1;
		o[i].second=b;
	}
	
	sort(o,o+n);
	reverse(o,o+n);
	int k=o[0].first;
   
	int i=0;
	while( k )
	{
		while( i < n && k == o[i].first )
		{
			bst.push(o[i].second);
			i++;
		}
		if(bst.size())
		{
		RES+=bst.top();
		bst.pop();
		}
	 
		 k--;
		
	}

    fprintf(g,"%lld\n",RES);
	fclose(f);
	fclose(g);
	return 0;
	
	
}