Pagini recente » Cod sursa (job #278136) | Cod sursa (job #805238) | Cod sursa (job #1896460) | Cod sursa (job #2435753) | Cod sursa (job #2332958)
#include <fstream>
#define NMAX 2005
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int v[NMAX], cost[NMAX], dp;
int main()
{
int n, c;
fin >> n >> c;
for(int i = 1; i <= n; ++i)
fin >> v[i] >> cost[i];
int maxxProf = 0;
for(int i = 1; i <= n; ++i)
{
int poz = 1;
while(poz <= n)
{
if(poz == 1)
{
dp = (cost[i] <= cost[1] ? cost[i] : 0) - c;
}
else
{
int x = (cost[i] <= cost[poz] ? cost[i] : 0) - c * (v[poz] - v[poz - 1]);
if(dp + x > (cost[i] <= cost[poz] ? cost[i] : 0) - c)
dp += x;
else
dp = (cost[i] <= cost[poz] ? cost[i] : 0) - c;
}
++poz;
maxxProf = max(maxxProf, dp);
}
}
fout << maxxProf << '\n';
return 0;
}