Cod sursa(job #3240594)

Utilizator amalia_ghicaAmalia Ghica amalia_ghica Data 18 august 2024 12:05:31
Problema Lupul Urias si Rau Scor 16
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.87 kb
#include <fstream>
#include <algorithm>

using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
struct JackDaniels{
    int d, a;
};
JackDaniels v[100001];
int cmp(JackDaniels x, JackDaniels y){
    if(x.d > y.d){
        return 0;
    }else if(x.d < y.d){
        return 1;
    }else{
        if(x.a > y.a){
            return 0;
        }else{
            return 1;
        }
    }
}
int main()
{
    int n, x, l, i, mx;
    long long sum = 0;
    fin >> n >> x >> l;
    for(i = 0; i < n; i++){
        fin >> v[i].d >> v[i].a;
    }
    sort(v, v + n, cmp);
    while(n > 0){
        mx = 0;
        for(i = n - 1; i >= 0  &&  v[i].d > (x - l); i--){
            if(v[i].a > mx){
                mx = v[i].a;
            }
        }
        n = i + 1;
        sum += mx;
        x -= l;
    }
    fout << sum;
    return 0;
}