Cod sursa(job #3141997)

Utilizator Ruxandra009Ruxandra Vasilescu Ruxandra009 Data 18 iulie 2023 11:49:33
Problema Lupul Urias si Rau Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.89 kb
#include <fstream>
#include <algorithm>
#define dist first
#define wool second

using namespace std;

ifstream f("lupu.in");
ofstream g("lupu.out");

const int nmax = 100005;
int prey, scared, n, sumi;
pair<int, int> A[nmax];

bool cmp(pair<int, int> x, pair<int, int> y)
{
    if(x.dist != y.dist)
        return (x.dist < y.dist);
    else
        return (x.wool > y.wool);
}

int main()
{
    f >> n >> prey >> scared;

    for(int i = 1; i <= n; i ++)
    {
        int x;
        f >> x >> A[i].wool;

        int nr = 0;
        while(x <= prey)
        {
            x += scared;
            nr ++;
        }
        A[i].dist = nr;
    }

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

    int run = 0;
    for(int i = 1; i <= n; i ++)
        if(A[i].dist - run)
        {
            sumi += A[i].wool;
            run ++;
        }

    g << sumi;
    return 0;
}