Cod sursa(job #1759409)

Utilizator PaulStighiStiegelbauer Paul-Alexandru PaulStighi Data 19 septembrie 2016 08:01:41
Problema Lupul Urias si Rau Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include<fstream>
#include<queue>
#include<vector>
#include<algorithm>
#define NMax 100005
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");

int N,X,L,Sol;
vector < pair<int,int> > V;

priority_queue <int> PQ;

void Read()
{
    fin>>N>>X>>L;

    for(int i = 1 ; i <= N ; ++i)
    {
        int a,b;    fin>>a>>b;
        a = ( X - a ) / L + 1;
        V.push_back(make_pair(a,b));
    }
}

bool Compare(pair<int,int> A,pair<int,int> B)
{
    return (A.first > B.first);
}

void Solve()
{
    sort(V.begin(),V.end(),Compare);

    int K = V[0].first;

    for(int i = V.size() ; i >= 0 ; )
    {
        while(V[i].first == K && i >= 0)
        {
            PQ.push(V[i].second);
            i--;
        }

        Sol += PQ.top();
        if(!PQ.empty()) PQ.pop();
        K--;
    }
}

void Print()
{
    fout<<Sol<<"\n";
}

int main()
{
    Read();
    Solve();
    Print();

    fin.close();
    fout.close();
    return 0;
}