Cod sursa(job #2031677)

Utilizator robx12lnLinca Robert robx12ln Data 3 octombrie 2017 17:56:31
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.95 kb
#include<fstream>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
int n, X, L, nr, pos;
long long sol;
pair<int,int> v[100005];
priority_queue< int, vector<int>, less<int> > q;
inline int cmp( const pair<int,int> &a, const pair<int,int> &b ){
    if( a.first == b.first )
        return a.second > b.second;
    return a.first > b.first;
}
int main(){
    fin >> n >> X >> L;
    for( int i = 1; i <= n; i++ ){
        fin >> v[i].first >> v[i].second;
        v[i].first = (X - v[i].first) / L;
        nr = max( v[i].first, nr );
    }
    sort( v + 1, v + n + 1, cmp );
    pos = 1;
    while( pos <= n && nr >= 0 ){
        while( pos <= n && v[pos].first == nr )
            q.push( v[pos].second ), pos++;
        if( !q.empty() ){
            sol += q.top();
            q.pop();
        }
        nr--;
    }
    fout << sol << "\n";
    return 0;
}