Cod sursa(job #992074)

Utilizator Impaler_009Mihai Nitu Impaler_009 Data 1 septembrie 2013 01:06:07
Problema Lupul Urias si Rau Scor 8
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <fstream>
#include <algorithm>

#define maxn 100001

using namespace std;

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

struct sheep
{
    int x,d;
}v[maxn];

int maxx[maxn],n,s,x,l;

inline bool cmp (const sheep &a, const sheep &b)
{
    return a.x<b.x;
}

int main()
{
    fin>>n>>x>>l;
    for (int i=1; i<=n; ++i)
        fin>>v[i].d>>v[i].x;

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

    int i=n,t=0;

    while (i>0)
    {
         while (i>0 && v[i].d + t*l > x) --i;
         s += v[i].x;
         ++t;
         --i;
    }

    fout<<s;
}