Cod sursa(job #1833919)

Utilizator PaulStighiStiegelbauer Paul-Alexandru PaulStighi Data 23 decembrie 2016 15:01:16
Problema Lupul Urias si Rau Scor 72
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.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;
long long 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)
{
    if(A.first < B.first)   return 0;

    if(A.first == B.first)  return (A.second > B.second);

    return 1;
}

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

    int K = V[0].first;

    for(int i = 0 ; i < V.size() ; )
    {
        while(V[i].first == K && i < V.size())
        {
            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;
}