Pagini recente » Rating Podeanu Andreea (Nutela) | Statistici extreme nimpho (frongeorgecosmin) | Cod sursa (job #325950) | Cod sursa (job #3237122) | Cod sursa (job #2332951)
#include <fstream>
#define NMAX 2005
using namespace std;
ifstream fin("carnati.in");
ofstream fout("carnati.out");
int v[NMAX], cost[NMAX];
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 p1 = 1, p2 = 2;
int prof = (cost[i] <= cost[1] ? cost[i] : 0) - c;
while(p2 <= n){
int lasProf = prof;
prof += (cost[i] <= cost[p2] ? cost[i] : 0) - c * (v[p2] - v[p2 - 1]);
if(prof < lasProf)
{
prof = prof - (cost[i] <= cost[p1] ? cost[i] : 0) + c * (v[p1 + 1] - v[p1]);
++p1;
}
if(prof > maxxProf)
maxxProf = prof;
++p2;
}
}
fout << maxxProf << '\n';
return 0;
}