Cod sursa(job #1067763)

Utilizator Athena99Anghel Anca Athena99 Data 27 decembrie 2013 14:55:23
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <algorithm>
#include <fstream>
#include <queue>

using namespace std;

ifstream fin("lupu.in");
ofstream fout("lupu.out");

typedef long long i64;

const int nmax= 100000;

struct str {
    int x, y;
};

bool comp ( str x, str y ) {
    return x.x<y.x;
}

str v[nmax+1];
priority_queue <int> q;

int main(  ) {
    int n, x, l;
    fin>>n>>x>>l;
    for ( int i= 1; i<=n; ++i ) {
        fin>>v[i].x>>v[i].y;
        v[i].x= (x-v[i].x+l)/l;
    }
    sort(v+1, v+n+1, comp);
    
    i64 sol= 0;
    int i= n, t= v[i].x;
    for ( ; t>0; --t ) {
        while ( i>0 && v[i].x==t ) {
            q.push(v[i].y);
            --i;
        }

        if ( !q.empty() ) {
            sol+= q.top();
            q.pop();
        } else if ( i>0 ) {
            t= v[i].x+1;
        }
    }

    fout<<sol<<"\n";

    return 0;
}