Cod sursa(job #3166815)

Utilizator TeodoraMaria123Serban Teodora Maria TeodoraMaria123 Data 9 noiembrie 2023 17:30:37
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.2 kb
#include <bits/stdc++.h>

using namespace std;

struct sheep
{
    int dist, cost;
};

class comp1
{
public:
    bool operator ()(const sheep &a, const sheep &b)
    {
        if(a.dist == b.dist)
            return a.cost < b.cost;
        return a.dist < b.dist;
    }
};

class comp
{
public:
    bool operator ()(const sheep &a, const sheep &b)
    {
//        if(a.dist == b.dist)
//            return a.cost < b.cost;
        return a.dist < b.dist;
    }
};

int n, x, l;
priority_queue <sheep, vector <sheep>, comp> pq;

int main()
{
    ios_base :: sync_with_stdio(0);
    cin.tie(0);

    freopen("lupu.in", "r", stdin);
    freopen("lupu.out", "w", stdout);

    cin >> n >> x >> l;

    for(int i = 1; i <= n; i ++)
    {
        int d, a;
        cin >> d >> a;
        if(d <= x)
            pq.push({d, a});
    }

    long long ans = 0;
    int cnt = 1;
    while(!pq.empty())
    {
        int maxWool = -1;
        while(!pq.empty()  &&  pq.top().dist > x - cnt * l)
        {
            maxWool = max(maxWool, pq.top().cost);
            pq.pop();
        }
        ans += maxWool;
        cnt ++;
    }

    cout << ans;
    return 0;
}