Pagini recente » Cod sursa (job #3237145) | Cod sursa (job #67714) | Cod sursa (job #1269844) | Cod sursa (job #532790) | Cod sursa (job #1220464)
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct pk{
int time,gain;
};
int n,c;
pk a[2005];
void solve(){
int localMax = 0;
int newJ,max = -(1 << 30);
bool entered = false;
for(int i = 0; i < n; i++){
newJ = 0;
localMax = 0;
entered = false;
for(int j = 0; j < n; j++){
if(a[i].gain <= a[j].gain){
entered = true;
int g = a[i].gain - abs(a[j].time - a[newJ].time) * c;
if(localMax + g >= a[i].gain)
localMax += g;
else
localMax = a[i].gain;
if(localMax > max)
max = localMax;
newJ = j;
}
else
if(entered == false)
newJ = j + 1;
}
}
if(max > c)
printf("%d\n",max - c);
else
printf("0\n");
}
int cmp(pk a, pk b)
{
return a.time < b.time;
}
int main(){
freopen("carnati.in","r",stdin);
freopen("carnati.out","w",stdout);
scanf("%d%d",&n,&c);
int g,t;
for(int i = 0; i < n; i++){
scanf("%d%d",&t,&g);
a[i].gain = g;
a[i].time = t;
}
sort(a,a+n,cmp);
solve();
return 0;
}