Cod sursa(job #3165188)

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

using namespace std;

#define MaxN 100000

struct oaie
{
    int dist, lana;

};

bool cmp(const oaie& a, const oaie& b)
{
    return a.lana<b.lana;
}

oaie v[MaxN];
int main()
{
    ifstream in("lupu.in");
    ofstream out("lupu.out");
    int n, x, l, rounds=0, i, maxrounds, res=0;
    long long mintime;
    in>>n>>x>>l;
    mintime=(long long)1 << 31;
    for(i=0; i<n; i++)
    {
        in>>v[i].dist>>v[i].lana;
        if(v[i].dist<mintime) mintime=v[i].dist;
    }
    maxrounds=(x-mintime)/l;
    make_heap(v, v+n, cmp);
    while(rounds<=maxrounds && n>0)
    {

        while(v[0].dist+rounds*l>x)
        {
            pop_heap(v, v+n, cmp);
            n--;
        }
        res+=v[0].lana; //cout<<res<<" ";
        pop_heap(v, v+n, cmp);
        n--;
        rounds++;
    }
    out<<res;

    return 0;
}