Pagini recente » Cod sursa (job #1384847) | Cod sursa (job #1400511) | Cod sursa (job #1072748) | Cod sursa (job #984261) | Cod sursa (job #1369006)
#include <fstream>
#include <algorithm>
#define NMax 2001
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
int n, c, d[NMax], i, j, bg, Max = -1;
struct oameni
{
int timp;
int pret;
}o[NMax];
int getmax(int a, int b)
{
if (a > b)
return a;
return b;
}
bool cmp(const oameni &o1, const oameni &o2)
{
return o1.timp < o2.timp;
}
int main()
{
f >> n >> c;
for (i = 1; i <= n; i++)
f >> o[i].timp >> o[i].pret;
o[0].timp = o[1].timp - 1;
for (i = 1; i <= n; i++) {
int pret = o[i].pret;
for (j = 1; j <= n; j++) {
if (o[j].pret >= pret)
d[j] = getmax(d[j - 1] - (o[j].timp - o[j - 1].timp) * c + pret, pret - c);
else
d[j] = getmax(d[j - 1] - (o[j].timp - o[j - 1].timp) * c, - c);
if (Max < d[j])
Max = d[j];
}
}
g << Max;
return 0;
}