Pagini recente » Cod sursa (job #2846198) | Cod sursa (job #1061504) | Cod sursa (job #2368450) | Cod sursa (job #798820) | Cod sursa (job #2697773)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin( "carnati.in" );
ofstream fout( "carnati.out" );
const int NMAX = 2000;
struct lol{
int x, y;
bool operator < (const lol &shit) const {
return x < shit.x;
}
};
lol v[NMAX + 1];
int cost[NMAX + 1];
int main() {
int n, i, j, sol, c;
fin >> n >> c;
for( i = 1; i <= n; ++i )
fin >> v[i].x >> v[i].y;
sort( v + 1, v + n + 1 );
v[0].x = v[1].x - 1;
sol = 0;
for( i = 1; i <= n; ++i )
for( j = 1; j <= n; ++j ){
cost[j] = 0;
if( v[i].y <= v[j].y )
cost[j] = v[i].y;
cost[j] = max(cost[j] - c, cost[j] + cost[j - 1] - (v[j].x - v[j - 1].x) * c);
sol = max(sol, cost[j]);
}
fout << sol;
return 0;
}