Cod sursa(job #1599122)

Utilizator redcrocodileIlies Andreea redcrocodile Data 13 februarie 2016 17:10:04
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.92 kb
#include <fstream>
#include <queue>

using namespace std;
ifstream f("lupu.in");
ofstream g("lupu.out");

typedef pair<int,int> pere;
long long sol;
priority_queue<pere> oisel,toate;
int x,l,n,dist;

void citire()
{
    pere oaie;
    int i;
    f>>n>>x>>l;
    for(i=1;i<=n;i++)
    {
        f>>dist>>oaie.second;
        if(dist<=x)
        {
          oaie.first=(x-dist)/l+1;
          toate.push(oaie);
        }
    }
}
void alegere()
{
    int i,n=x/l+1;
    pere oaie;
    sol=0;
    for(i=n;i>=1;i--)
    {
        while(!toate.empty() and toate.top().first>=i)
        {
           oaie.first=toate.top().second;
           oaie.second=toate.top().first;
           oisel.push(oaie);
           toate.pop();
        }
        if(!oisel.empty())
        {sol+=oisel.top().first;
        oisel.pop();}
    }
}
int main()
{
    citire();
    alegere();
    g<<sol;
    return 0;
}