Cod sursa(job #2576642)

Utilizator Antonio03Dumitru Antonio Antonio03 Data 6 martie 2020 21:20:58
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.74 kb
#include <bits/stdc++.h>

using namespace std;

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

priority_queue <int> Q;

struct nod
{

    int x, y;

}v[100001];

bool cmp(nod i, nod j)
{
    return i.x < j.x;

}

int n, d, k, i, lim, val;
long long s;

int main()
{
    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;
    while(lim <= d && i <= n)
    {
        while(i <= n && v[i].x <= lim)
        {
            Q.push(v[i].y);
            i ++;
        }
        if(!Q.empty())
        {
            val = Q.top();
            s = s + val;
            Q.pop();
        }
        lim = lim + k;
    }
    g << s;
    return 0;

}