Cod sursa(job #1320659)

Utilizator stanescu.raduRadu Stanescu stanescu.radu Data 18 ianuarie 2015 11:53:13
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul II Marime 0.9 kb
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>

#define PB push_back
#define MP make_pair

using namespace std;
  
ifstream f ("lupu.in");
ofstream g("lupu.out");
  
int n, x, l;
pair <int, int> X;
vector <pair<int,int> > v;
long long sol = 0;
  
int maxx = -999999999;
  
priority_queue <int> Q;
  
int main()
{
    f >> n >> x >> l;
    for (int i = 1; i <= n; i++)
    {
        f >> X.first >> X.second;
        if (X.first <= x)
        {
            X.first = (x - X.first) / l;
            maxx = max(maxx, X.first);
            v.PB(X);
        }
    }
	
    sort(v.begin(),v.end());
    int j = v.size() - 1;
    
    for (int i = maxx; i >= 0; i--)
    {
        for (j; v[j].first == i && j >= 0; j--)
            Q.push(v[j].second);
		
        if (!Q.empty())
            sol += Q.top() ,Q.pop();
    }
    g << sol;
	return 0;
}