Pagini recente » Cod sursa (job #2095318) | Cod sursa (job #2454145) | Cod sursa (job #1142142) | Cod sursa (job #2561307) | Cod sursa (job #1360975)
#include<fstream>
#include<algorithm>
using namespace std;
struct x2{
int t;
int p;
};
x2 x[2003];
int cmp(x2 x, x2 y){
return x.t<y.t;
}
int n, cost, i, j, best[2003], sol;
ifstream in("carnati.in");
ofstream out("carnati.out");
int main(){
in>>n>>cost;
for(i=1; i<=n; i++)
in>>x[i].t>>x[i].p;
sort(x+1, x+n+1, cmp);
for(j=1; j<=n; j++){
for(i=1; i<=n; i++){
best[i]=0;
if(x[i].p>=x[j].p)
best[i]=x[j].p;
best[i]=max(best[i]-cost, best[i]+best[i-1]-(x[i].t-x[i-1].t)*cost);
if(best[i]>sol)
sol=best[i];
}
}
out<<sol;
return 0;
}