Pagini recente » Cod sursa (job #1324057) | Cod sursa (job #2353446) | Cod sursa (job #1839260) | Cod sursa (job #1168204) | Cod sursa (job #1220385)
#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 >= g){
localMax += g;
newJ = j;
}
else{
localMax = g;
newJ = j + 1;
}
if(localMax > max)
max = localMax;
}
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;
}