Cod sursa(job #1921688)

Utilizator RaresEGaySopterean Adrian RaresEGay Data 10 martie 2017 13:52:56
Problema Lupul Urias si Rau Scor 48
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>
#include <iostream>
#include <queue>

#define INF 0x3f3f3f3f
#define maxn 100005

using namespace std;

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

priority_queue <int> pq;

int n, d, l, sol;
int tmaxim = -INF;

struct {
    int tmax, dist, lana;
}v[maxn];

int main (){
    f >> n >> d >> l;
    for(int i = 1; i <= n; ++i){
        f >> v[i].dist >> v[i].lana;
        v[i].tmax = (d - v[i].dist) / l + 1;
        tmaxim = max(tmaxim, v[i].tmax);
    }

    for(int i = tmaxim; i >= 1; --i){
        for(int j = 1; j <= n; ++j){
            if(v[j].tmax == i) pq.push(v[j].lana);
        }
        sol += pq.top();
        pq.pop();
    }
    g << sol << ' ';
}