Cod sursa(job #1282190)

Utilizator pavlov.ionPavlov Ion pavlov.ion Data 3 decembrie 2014 23:38:26
Problema Lupul Urias si Rau Scor 88
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul II Marime 0.81 kb
#include<fstream>
#include<algorithm>
#include<queue>
#define MAXN 100005
#define LL long long
using namespace std;
ifstream cin("lupu.in");
ofstream cout("lupu.out");
int N,X,L;
LL S;
struct oaie{
	   int dist;
	   int profit;
	   int timp;
} V[MAXN];
priority_queue<int> Q;
bool cmp(oaie a,oaie b)
{
 	 return (a.timp>b.timp);
}
int main() {
   cin>>N>>X>>L;
   for(int i=0;i<N;i++){
   		     cin>>V[i].dist;
   		     cin>>V[i].profit;
   		     V[i].timp=(X-V[i].dist)/L;
   }          
   sort(V,V+N,cmp);
   int Tmax=V[0].timp;
   //solve
   int i,j;
   for(j=Tmax,i=0;j>=0;j--)	{	
      	 for(;i<N && j==V[i].timp;i++)
		                       Q.push(V[i].profit);
   					              			            
		 S=S+Q.top();
		 Q.pop();
   }
   cout<<S;
   return 0;	                   
}