Cod sursa(job #3167744)

Utilizator pitradaPit-Rada Ionel-Vasile pitrada Data 11 noiembrie 2023 07:15:41
Problema Lupul Urias si Rau Scor 8
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <fstream>
#include <algorithm>
#define nmax 102
using namespace std;
ifstream  fin("lupu.in");
ofstream fout("lupu.out");
int N,X,L,D[nmax],A[nmax],idx[nmax],i;
long long p,q,amax,smax;
int cmp(int p, int q){
    if(D[p]<D[q])return 1;
    if(D[p]==D[q] && A[p]>A[q])return 1;
    return 0;
}
int main()
{
    fin>>N>>X>>L;
    for(int i=1;i<=N;i++){
        fin>>D[i]>>A[i];
        idx[i]=i;
    }
    sort(idx+1,idx+1+N,cmp);
    smax=0;
    i=N;
    q=X;
    p=q-(L-1);
    if(p<0)p=0;
    while(p<=q){
        amax=0;
        while(i>=1 && D[idx[i]]>=p){
            if(A[idx[i]]>amax){
                amax=A[idx[i]];
            }
            i--;
        }
        smax=smax+amax;
        q=q-L;
        p=q-(L-1);
        if(p<0)p=0;
    }
    fout<<smax;
    return 0;
}