Cod sursa(job #3165204)

Utilizator biancaivascuBianca Ivascu biancaivascu Data 5 noiembrie 2023 17:22:26
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.01 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <algorithm>

using namespace std;

#define MaxN 100000
struct oaie
{
    int dist, lana;

};

bool cmp(const oaie& a, const oaie& b)
{
    return a.dist>b.dist;
}
oaie v[MaxN];

priority_queue <int> pq;
int main()
{
    ifstream in("lupu.in");
    ofstream out("lupu.out");
    int n, x, l, rounds=0, i, maxrounds, cnt=0, a, b, j;
    long long int res=0;
    in>>n>>x>>l;
    for(i=0; i<n; i++)
    {
        in>>a>>b;
        if(a<=x)
        {
            v[cnt].dist=(x-a)/l;
            if(v[cnt].dist>maxrounds) maxrounds=v[cnt].dist;
            v[cnt].lana=b;
            cnt++;
        }
    }
    sort(v, v+cnt, cmp);
    j=0;
    for(i=maxrounds; i>=0; i--)
    {
        while(j<cnt && v[j].dist==i)
        {
            pq.push(v[j].lana);
            j++;
        }
        if(pq.size()>0)
        {
            res+=pq.top();
            pq.pop();
        }

    }
    out<<res;
    return 0;
}