Cod sursa(job #2811315)

Utilizator AleXutzZuDavid Alex Robert AleXutzZu Data 1 decembrie 2021 20:18:07
Problema Lupul Urias si Rau Scor 32
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.99 kb
#include <fstream>
#include <vector>
#include <queue>
#include <algorithm>

struct Sheep {
private:

public:
    size_t distance = 0, max_step = 0, wool = 0;
};

int main() {
    std::ifstream input("lupu.in");
    std::ofstream output("lupu.out");

    std::priority_queue<size_t> woolQueue;
    size_t n, wolf_max_distance, increment, max_step = 0;
    std::vector<Sheep> sheep;
    input >> n >> wolf_max_distance >> increment;
    for (size_t i = 0; i < n; ++i) {
        Sheep a;
        input >> a.distance >> a.wool;
        a.max_step = (wolf_max_distance - a.distance) / increment + 1;
        sheep.push_back(a);
        if (a.max_step > max_step) max_step = a.max_step;
    }
    size_t total_wool = 0;
    for (size_t i = max_step; i >= 1; --i) {
        for (size_t j = 0; j < n; ++j) if (sheep[j].max_step == i) woolQueue.push(sheep[j].wool);

        total_wool += woolQueue.top();
        woolQueue.pop();
    }

    output << total_wool;

    input.close();
    output.close();
    return 0;
}