Cod sursa(job #3165201)

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

using namespace std;

#define MaxN 100000

struct oaie
{
    int dist, lana;

};

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, res=0, cnt=0, a, b, j;
    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++;
        }
    }
    for(i=maxrounds; i>=0; i--)
    {
        for(j=0; j<cnt; j++)
        {
            if(v[j].dist==i)
            {
                pq.push(v[j].lana);
            }
        }
        if(pq.size()>0)
        {
            res+=pq.top();
            pq.pop();
        }

    }
    out<<res;
    return 0;
}