Cod sursa(job #1844810)

Utilizator cameleonGeorgescu Dan cameleon Data 10 ianuarie 2017 15:17:40
Problema Lupul Urias si Rau Scor 28
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include<fstream>
#include<algorithm>
#define Nmax 100005
using namespace std;
ifstream fin("lupu.in");
ofstream fout("lupu.out");
struct oita{
    int lana,coef;
};
int X, L, N;
oita v[Nmax];
long long totalLana;
bool cmp(oita x, oita y){
    if(x.coef<y.coef || x.coef==y.coef && x.lana>y.lana)
        return true;
    return false;
}
int main(){
    int d, cant,k=0,cmax=0,cf;
    fin>>N>>X>>L;
    for(int i=1;i<=N;i++){
        fin>>d>>cant;
        if(d<=X){
            k++;
            v[k].lana=cant;
            v[k].coef=(X-d)/L;
            cmax=max(cmax,v[k].coef);
        }
    }

    sort(v+1,v+N+1,cmp);

    cf=0;
    for(int i=1;i<=k;i++)
        if(v[i].coef>=cf){
            totalLana+=v[i].lana;
            cf++;
        }
    fout<<totalLana;



    return 0;
}