Cod sursa(job #1834441)

Utilizator oldatlantianSerban Cercelescu oldatlantian Data 24 decembrie 2016 16:52:52
Problema Lupul Urias si Rau Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <bits/stdc++.h>
using namespace std;

typedef long long i64;

const int NMAX = 1e5 + 5;

priority_queue<int> pq;

vector<int> tempus[NMAX];

int main(void) {
    ifstream fi("lupu.in");
    ofstream fo("lupu.out");
    int n, x, l, t, g;
    i64 ant;

    ant = 0LL;

    fi >> n >> x >> l;
    for (int i = 0; i < n; ++i) {
        fi >> t >> g;
        if (t <= x)
            tempus[(x - t) / l].push_back(g); }

    for (int i = n; i >= 0; --i) {
        for (auto j: tempus[i])
            pq.push(j);
        if (!pq.empty()) {
            ant+= pq.top();
            pq.pop(); } }

    fo << ant << '\n';

    return 0; }

// :<