Cod sursa(job #2751802)

Utilizator Vlad_AnicaAnica-Popa Vlad-Ioan Vlad_Anica Data 15 mai 2021 20:37:00
Problema Lupul Urias si Rau Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <iostream>
#include <fstream>
#include <bits/stdc++.h>
#include <algorithm>

using namespace std;
const int NMAX = 1e5;

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

struct oaie
{
    int lana, runda;
};

bool cmp(oaie a, oaie b);

priority_queue<int> myHeap;
oaie arr[NMAX + 1];

int main()
{
    int n, x, l, i, dist, r;
    long long smax;
    fin >> n >> x >> l;
    for (i = 0; i < n; i++)
    {
        fin >> dist >> arr[i].lana;
        arr[i].runda = (x - dist) / l + 1;
    }
    arr[n].runda = 0;
    sort(arr, arr + n, cmp);

    smax = 0;
    i = 0;
    for (r = arr[0].runda; r > 0; r--)
    {
        while (arr[i].runda == r)
        {
            myHeap.push(arr[i].lana);
            i++;
        }
        if (!myHeap.empty())
        {
            smax += (long long)myHeap.top();
            myHeap.pop();
        }
    }
    fout << smax;

    return 0;
}

bool cmp (oaie a, oaie b)
{
    return a.runda > b.runda;
}