Cod sursa(job #1322094)

Utilizator obidanDan Ganea obidan Data 19 ianuarie 2015 19:27:59
Problema Lupul Urias si Rau Scor 8
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2014, Anul I Marime 0.99 kb
#include <fstream>
#include <algorithm>
using namespace std;

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

const int NMax = 100002;


struct Oi{
int d,l; //distanta , lana
}Sheep[NMax];

bool SheepComp(Oi A, Oi B)
{
    return A.d > B.d ;
}

int main()
{
    int n,x,l,i,j,st,dr;
    f>>n>>x>>l;
    for(i=1;i<=n;i++)
    {
        f>>Sheep[i].d>>Sheep[i].l;
    }

    sort(Sheep+1,Sheep+n+1,SheepComp);


    dr = Sheep[1].d;
    st = Sheep[1].d - l + 1;
    // Luam din intervalul [st,dr]
    i=1;
    long long int tempmax;
    long long int result= 0;
    while(dr>=0)
    {
       // g<<st<<" "<<dr<<endl;
        tempmax = 0;
        while(Sheep[i].d <= dr && st <= Sheep[i].d  && i<=n)
        {
            if(  Sheep[i].d <= x && Sheep[i].l > tempmax)
                {
                    tempmax = Sheep[i].l;
                }
            i++;
        }
        result = result + tempmax;
        dr=dr-l;
        st=st-l;
    }
    g<<result;
}