Cod sursa(job #1833926)

Utilizator PaulStighiStiegelbauer Paul-Alexandru PaulStighi Data 23 decembrie 2016 15:26:37
Problema Lupul Urias si Rau Scor 16
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include<fstream>
#include<iostream>
#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;

        if(a <= X)
        {
            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);

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

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

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

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

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