Cod sursa(job #1389774)

Utilizator andreey_047Andrei Maxim andreey_047 Data 16 martie 2015 17:19:09
Problema Lupul Urias si Rau Scor 16
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <iostream>
#include <cstdio>
#include <algorithm>
#define nmax 100005
using namespace std;
int n,x,len,m,best;
long long sum;
struct Coord{
    int d,b;
};
Coord a[nmax];
inline  bool cmp(const Coord A,const Coord B){
    if(A.d == B.d) return A.b > B.b;
 return A.d > B.d;
}
int main(){
    int i,j,ok;
    freopen("lupu.in","r",stdin);
    freopen("lupu.out","w",stdout);
    scanf("%d%d%d",&n,&x,&len);
    for(i=1;i<=n;i++){
        scanf("%d%d",&a[i].d,&a[i].b);
    }
    sort(a+1,a+n+1,cmp);
    for(i=1;i<=n;i++){
            best=ok=0;
      if(a[i].d + len*m <= x){
        for(j=i;j<=n&&!ok;j++)
            if(a[j].d+len*m+len > x)best=max(best,a[j].b);
            else break;
        i=j-1;
        m++;
        sum+=best;
      }}
      cout<<sum<<'\n';
    return 0;
}