Cod sursa(job #764859)

Utilizator vendettaSalajan Razvan vendetta Data 6 iulie 2012 15:27:19
Problema Lupul Urias si Rau Scor 32
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <fstream>
#include <iostream>
#include <set>
#include <algorithm>

using namespace std;

#define x first
#define y second
#define nmax 100005

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

set<int, greater<int> > lana;
typedef struct {int t, lana;}camp;
camp a[nmax];
int n, X, L;
long long s;

bool cmp(camp const &a, camp const &b){

    return (a.t < b.t);

}

void citeste(){

    f >> n >> X >> L;

    for(int i=1; i<=n; i++){
        int d, val;
        f >> d >> val;
        a[i].t = (X-d)/L + 1;
        a[i].lana = val;
    }

    sort(a+1, a+n+1, cmp);

}

void rezolva(){

    for(int i=a[n].t, j=n; i>=1; i--){
        while(a[j].t == i && j>=1){
            lana.insert(a[j].lana);
            --j;
        }
        if (lana.size()){
            s += 1LL*(*lana.begin());
            lana.erase(lana.begin());
        }
    }

    g << s << "\n";

}

int main(){

    citeste();
    rezolva();

    f.close();
    g.close();

    return 0;

}