Cod sursa(job #1127384)

Utilizator projectanduFMI Stanescu Andrei Alexandru projectandu Data 27 februarie 2014 12:15:25
Problema Lupul Urias si Rau Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");

const int N=1+1e6;
struct Oaie{
    int d,l;
};

priority_queue<int> h;
Oaie o[N];
int n,x,f,k;
bool cmp(Oaie a, Oaie b){
    return a.d>b.d;
}
int main()
{
    int a,b;
    in>>n>>x>>f;
    for(int i=1 ; i<=n ; i++){
        in>>a>>b;
        if(a<=x){
            o[++k].d=a;
            o[k].l=b;
        }
    }
    sort(&o[1], &o[k+1], cmp);
    for(int i=1 ; i<=k ; i++){
        if( o[i].d + (h.size())*f <=x){
            h.push(-o[i].l);
        }else{
            if(-o[i].l<h.top()){
                h.pop();
                h.push(-o[i].l);
            }
        }
    }
    int s=0;
    while(!h.empty()){
        s+=h.top();
        h.pop();
    }
    out<<-s;
    return 0;
}