Cod sursa(job #2286657)

Utilizator TooHappyMarchitan Teodor TooHappy Data 20 noiembrie 2018 16:56:43
Problema Lupul Urias si Rau Scor 8
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>
 
using namespace std;
 
ifstream in("lupu.in");
ofstream out("lupu.out");

int main() {
    ios::sync_with_stdio(false); in.tie(0); out.tie(0);
    
    int n, x ,l; in >> n >> x >> l;

    priority_queue< pair< int, int > > pq;
    for(int i = 0; i < n; ++i) {
        int d, a; in >> d >> a;

        pq.push({a, d});
    }

    int ans = 0;
    while(!pq.empty()) {
        if(pq.top().second <= x) {
            ans += pq.top().first;
            x -= l;
        }

        pq.pop();
    }

    out << ans << "\n";

    in.close(); out.close();
 
    return 0;
}