Cod sursa(job #2064631)

Utilizator andrei32576Andrei Florea andrei32576 Data 12 noiembrie 2017 17:17:24
Problema Lupul Urias si Rau Scor 8
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include<fstream>
#include<algorithm>
using namespace std;

int n,x,l,i,ct;
long long s;
struct oaie{int d,c;};
oaie v[100010];

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

bool comp(oaie a,oaie b)
{
    if(a.c>b.c) return 1;
    if(a.c==b.c && a.d>b.d) return 1;
    return 0;
}

int main()
{
    f>>n>>x>>l;

    for(i=1;i<=n;i++)
        f>>v[i].d>>v[i].c;

    sort(v+1,v+n+1,comp);

    ct=0;
    for(i=1;i<=n;i++)
    {
        if(v[i].d+ct*l<=x)
        {
            ct++;
            s+=v[i].c;
        }
    }

    g<<s;

    f.close();
    g.close();
    return 0;
}