Pagini recente » Cod sursa (job #638994) | Cod sursa (job #2293171) | Cod sursa (job #212060) | Cod sursa (job #1026446) | Cod sursa (job #1386665)
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream is("carnati.in");
ofstream os("carnati.out");
int op[2002];
pair<int, int> p[2002];
int n, c;
int x, profmax = -1;
int main()
{
is >> n >> c;
int a, b;
for ( int i = 1; i <= n; ++i )
{
is >> a >> b;
p[i] = pair<int, int>(a, b);
}
sort(p + 1, p + n + 1);
p[0].first = p[0].second = -10;
for ( int i = 1; i <= n; ++i )
for ( int j = 1; j <= n; ++j )
{
x = p[i].second;
if ( p[j].second < x )
x = 0;
if ( op[j - 1] - (p[j].first - p[j - 1].first) * c + x < x - c )
op[j] = x - c;
else
op[j] = op[j - 1] - (p[j].first - p[j - 1].first) * c + x;
profmax = max(profmax, op[j]);
}
os << profmax;
is.close();
os.close();
return 0;
}