Pagini recente » Cod sursa (job #2141071) | Cod sursa (job #1466413) | Cod sursa (job #2568265) | Cod sursa (job #2887656) | Cod sursa (job #1374991)
#include <iostream>
#include <fstream>
#include <algorithm>
#define LL long long
using namespace std;
struct el{
LL t,p;
};
LL N,C,dp[2010]; el a[2010];
inline bool cmp(el A, el B){
return (A.t<B.t);
}
LL f(LL x, LL v){
if (x<v) return 0;
return v;
}
int main(){
ifstream fin("carnati.in");
ofstream fout("carnati.out");
fin >> N >> C;
int i,j; LL MAX=0,res=0;
for (i=1; i<=N; i++) fin >> a[i].t >> a[i].p;
sort(a+1,a+N+1,cmp);
for (i=1; i<=N; i++){
dp[1]=f(a[1].p,a[i].p)-C;
MAX=dp[1];
for (j=2; j<=N; j++){
dp[j]=max(f(a[j].p,a[i].p)-C,dp[j-1]+f(a[j].p,a[i].p)-(a[j].t-a[j-1].t)*C);
MAX=max(MAX,dp[j]);
}
res=max(MAX,res);
}
fout << res << "\n";
return 0;
}