Cod sursa(job #3363230)

Utilizator The_WiskmasterStefan Vilsanescu The_Wiskmaster Data 14 august 2026 13:17:43
Problema Lupul Urias si Rau Scor 8
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb

#include <iostream>
#include <fstream>
#include <algorithm>
#include <queue>

using namespace std;

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

int n,x,l;

struct lup{
    int d,b;
}v[100005];

bool cmp(lup a,lup b)
{
    return a.d>b.d;
}

priority_queue<int> q;

int main()
{
    fin>>n>>x>>l;

    for(int i=1;i<=n;i++)
        fin>>v[i].d>>v[i].b;

    sort(v+1,v+n+1,cmp);

    long long s=0;
    int p=1;
    int t=x%l;

    while(t<=x)
    {
        while(p<=n&&v[p].d>t)
        {
            q.push(v[p].b);
            p++;
        }

        if(!q.empty())
        {
            s+=q.top();
            q.pop();
        }

        t+=l;
    }

    g<<s;

    fin.close();
    g.close();
    return 0;
}