Pagini recente » Cod sursa (job #2296443) | Cod sursa (job #2638760) | Cod sursa (job #2395142) | Cod sursa (job #2505936) | Cod sursa (job #2293144)
#include <bits/stdc++.h>
#define int long long
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
const int VM(2005) ;
int n, c, ans ;
struct DC {
int x, y ;
bool operator < (const DC& other) const {
return this->x < other.x;
}
}v[VM];
int Baga(int pret) {
int profc(0), profm(1 << 31) ;
register int i ;
for (i = 1 ; i <= n ; ++ i) {
profc = MAX(profc - (v[i].x - v[i - 1].x) * c, 0);
if(pret <= v[i].y)
profc += pret;
profm = MAX(profm, profc - c);
}
return profm ;
}
int32_t main() {
freopen("carnati.in", "r", stdin) ;
freopen("carnati.out", "w", stdout) ;
register int i ;
scanf("%lld %lld", &n, &c) ;
for (i = 1 ; i <= n ; ++ i)
scanf("%lld %lld", &v[i].x, &v[i].y) ;
std::sort(v + 1,v + 1 + n) ;
for (i = 1 ; i <= n ; ++ i)
ans = MAX(ans, Baga(v[i].y)) ;
printf("%lld", ans) ;
return 0;
}