Cod sursa(job #2795560)

Utilizator MihaiZ777MihaiZ MihaiZ777 Data 6 noiembrie 2021 16:27:53
Problema Lupul Urias si Rau Scor 80
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.46 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <queue>
using namespace std;

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

struct sheep {
    int dist;
    int amount;

    inline bool operator < (const sheep&  other) const
    {
        return this->amount < other.amount;
    }
};

bool cmp(const sheep& a, const sheep& b)
{
    return a.dist < b.dist;
}


priority_queue <sheep>myQueue;


sheep sheeps[100005];

int main() {
    int n, dist, move;
    fin >> n >> dist >> move;

    for (int i = 0; i < n; i++) {
        int x, y;
        fin >> x >> y;
        sheeps[i] = {x, y};
    }

    sort(sheeps + 0, sheeps + n, cmp);
    int wave = 1;
    int ans = 0;


    int maxWave = dist / move;
    
    int index = 0;
    // for (int i = 0; i < n; i++)
    // {
    //     cout << sheeps[i].dist << ' ' << sheeps[i].amount << '\n';
    // }
    // cout << '\n';


    for (int i = 0; i < maxWave + 1; i++)
    {
        //cout << '\n' << "OK" << '\n';
        while (sheeps[index].dist <= i * move && sheeps[index].dist <= dist && index < n)
        {
            //cout << sheeps[index].dist << ' ';
            myQueue.push(sheeps[index]);
            index++;
        }
        if (myQueue.empty())
        {
            continue;
        }
        //cout << "***" << myQueue.top().amount;
        ans += myQueue.top().amount;

        myQueue.pop();
    }
    fout << ans << '\n';
}