Pagini recente » Cod sursa (job #2419353) | Cod sursa (job #1173217) | Cod sursa (job #432535) | Cod sursa (job #742292) | Cod sursa (job #1595261)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("carnati.in");
ofstream g("carnati.out");
int n, c, i, j, s, maxim, p, max1;
struct carne
{
int pret, timp;
}a[2001];
bool cmp(carne a, carne b)
{
return (a.timp < b.timp);
}
int main()
{
f >> n >> c;
for (i = 1; i <= n; i++)
f >> a[i].timp >> a[i].pret;
sort(a+1, a+n+1, cmp);
for (i = 1; i <= n; i++)
{
max1 = a[i].pret, s = 0;
for (j = 1, s = 0; j <= n; j++)
{
p = 0;
if (a[j].pret >= max1)
p = max1;
if (s - (a[j].timp - a[j-1].timp)*c > 0)
s += p - (a[j].timp - a[j-1].timp)*c;
else
s = p-c;
if (s > maxim)
maxim = s;
}
}
g << maxim;
return 0;
}