Cod sursa(job #2418085)

Utilizator TheNextGenerationAyy LMAO TheNextGeneration Data 3 mai 2019 15:41:17
Problema Lupul Urias si Rau Scor 8
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <bits/stdc++.h>
using namespace std;
ifstream in("lupu.in");
ofstream out("lupu.out");
const int N = 1e5+5;
typedef long long ll;
priority_queue< pair<ll,ll> > q;
int main()
{
    int n,x;
    ll l,c = 0;
    in >> n >> x >> l;
    for (int i = 1; i<=n; i++)
    {
        pair<ll,ll> t;
        in >> t.second >> t.first;
        q.push(t);
    }
    ll s = 0;
    while (!q.empty())
    {
        while (!q.empty() && q.top().second+c*l>x)
            q.pop();
        if (!q.empty())
        {
            c++;
            s+=q.top().first;
            q.pop();
        }
    }
    out << s;
}