Cod sursa(job #3005438)

Utilizator Roxana_3Asavei Roxana Roxana_3 Data 16 martie 2023 23:32:25
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.21 kb
#include <bits/stdc++.h>
#define N 100000
using namespace std;

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

int n, x, l;
struct oaie
{
    int dist;
    int cant;
} a[N + 5];

///multiset<int> ms;
long long cant_max;

void Citire()
{
    fin >> n >> x >> l;
    for(int i = 1; i <= n; ++i)
        fin >> a[i].dist >> a[i].cant;
}

inline bool comp(oaie x, oaie y)
{
    return x.dist > y.dist || (x.dist == y. dist && x.cant > y. cant);
}

int Maxim(int a, int b)
{
    return a > b ? a : b;
}

void Rezolvare()
{
    int j = 1;
    int val_max;
    while(x - l >= 0)
    {
        x = x - l;
        val_max = 0;
        while(a[j].dist > x && j <= n)
        {
            val_max = Maxim(val_max, a[j].cant);
            j++;
        }
        cant_max += val_max;
    }

    val_max = 0;
    while(j <= n)
    {
        val_max = Maxim(val_max, a[j].cant);
        j++;
    }

    cant_max += val_max;

    fout << cant_max;

}

int main()
{
    Citire();
    fin.close();
    ///sortam descresc dupa dist: le iau prima data pe cele cu sansele mai mari sa scape
    sort(a + 1, a + n + 1, comp);
    Rezolvare();
    fout.close();

    return 0;
}