Cod sursa(job #2862071)

Utilizator GabiRB1Rafael GabiRB1 Data 4 martie 2022 20:50:28
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<bits/stdc++.h>
using namespace std;
priority_queue<int> Q;
int d, k, n, i, lim, val;
long long s;
struct nod
{
    int x,y;
} v[100006];
int cmp(const nod a, const nod b)
{
    return a.x < b.x;
}
int main ()
{
    ifstream f("lupu.in");
    ofstream g("lupu.out");
    f >> n >> d >> k;
    for(i = 1; i <= n; i ++)
        f >> v[i].x >> v[i].y;
    sort(v + 1, v + n + 1, cmp);
    i = 1;
    for(lim = 0; lim <= d && i <= n; lim = lim + k)
    {
        for(i = i; i <= n && v[i].x <= lim; i ++)
            Q.push(v[i].y);
        if(!Q.empty())
        {
            val=Q.top();
            s = s + val;
            Q.pop();
        }
    }
    g << s << "\n";
    return 0;
}