Cod sursa(job #3178779)

Utilizator paull122Paul Ion paull122 Data 2 decembrie 2023 14:35:01
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
#define MOD 666013

struct node
{
    int d,v;
};

priority_queue<int> heap;


node a[100001];
int heapsize;
int n,l,dx,x;
bool cmp(node a,node b)
{
    return a.d < b.d;
}
int main()
{
    fin >> n >> x >> l;
    for(int i=1;i<=n;i++)
    {
        fin >> a[i].d >> a[i].v;
    }
    sort(a+1,a+n+1,cmp);

    ll res=0;
    int i=1;
    int d=x%l;
    while(d <= x)
    {
        while(i <=n && a[i].d  <= d)
        {
            heap.push(a[i].v);
            i++;
        }
        if(!heap.empty())
        {
            res += heap.top();
            heap.pop();
        }
        d += l;
    }

    fout << res;
}