Pagini recente » Cod sursa (job #1881062) | Cod sursa (job #2224322) | Cod sursa (job #2549911) | Cod sursa (job #2812023) | Cod sursa (job #2759707)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int n, c, dp[2005];
struct comanda{
int t, p;
bool operator < (comanda &c) const {
return t < c.t;
}
}v[2005];
int main(){
fin >> n >> c;
for (int i = 1; i <= n; ++i){
fin >> v[i].t >> v[i].p;
}
sort(v + 1, v + n + 1);
int ans = 0;
for (int i = 1; i <= n; ++i){
int x = v[i].p;
memset(dp, 0, sizeof dp);
for (int j = 1; j <= n; ++j){
if (v[j].p >= x){
dp[j] = max(dp[j], x);
dp[j] = max(dp[j], x + dp[j - 1] -(v[j].t - v[j - 1].t) * c);
}
else{
dp[j] = max(dp[j], dp[j - 1] - (v[j].t - v[j - 1].t) * c);
}
ans = max(ans, dp[j]);
}
}
ans = max(0, ans - c);
fout << ans;
fin.close();
fout.close();
return 0;
}