Cod sursa(job #2964747)

Utilizator Luca_CristianZamfir Luca-Cristian Luca_Cristian Data 13 ianuarie 2023 20:40:32
Problema Lupul Urias si Rau Scor 32
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <fstream>
#include <queue>
#include <algorithm>

using namespace std;


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

#define int long long
const int Nmax = 1e5 + 5;
pair <int ,int> vsheep[Nmax];

bool cmp(pair <int, int> a, pair <int, int> b)
{
    return a.first > b.first;
}

signed main()
{
    int n, x, l, i;

    fin >> n >> x >> l;
    for(i = 1; i <= n; i++)
    {
        fin >> vsheep[i].first >> vsheep[i].second;

        vsheep[i].first = (x - vsheep[i].first) / l;
    }

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

    /*for(i = 1; i <= n; i++)
        fout << vsheep[i].first << " " << vsheep[i].second << '\n';*/

    int timp = vsheep[1].first, ans = 0;

    priority_queue <int> pq;
    i = 1;
    while(i <= n && timp >= 0)
    {
        int timpc = vsheep[i].first;
        while(vsheep[i].first == timpc && i <= n)
        {
            pq.push(vsheep[i].second);
            i++;
        }

        if(!pq.empty())
        {
            ans += pq.top();
            pq.pop();
        }
        timp--;
    }

    fout << ans;
    return 0;
}