Cod sursa(job #1282161)

Utilizator pavlov.ionPavlov Ion pavlov.ion Data 3 decembrie 2014 23:27:27
Problema Lupul Urias si Rau Scor 44
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul II Marime 0.82 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");
LL N,X,L,S;
struct oaie{
	   LL dist;
	   LL profit;
	   LL timp;
} V[MAXN];
priority_queue<LL> 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);
   LL Tmax=V[0].timp;
   //solve
   LL i,j;
   for(int j=Tmax;j>=0;j--)	{	
      	 for(int i=0;i<N;i++)
		         if(j==V[i].timp)
		                   Q.push(V[i].profit);
   					              			            
		 S=S+Q.top();
		 Q.pop();
   }
   cout<<S;
   return 0;	                   
}