Pagini recente » Cod sursa (job #436608) | Cod sursa (job #996180) | Cod sursa (job #2844309) | Cod sursa (job #1425679) | Cod sursa (job #137199)
Cod sursa(job #137199)
#include <stdio.h>
long max, profit, i, n, maxim, max2, j, pret, c, v[2048], m[2048];
struct lol
{
long h, p;
};
lol buyer[2048];
int main()
{
freopen ("carnati.in", "rt", stdin);
freopen ("carnati.out", "wt", stdout);
scanf("%ld %ld", &n, &c);
for (i = 1; i <= n; i ++)
{
scanf("%ld %ld", &buyer[i].h, &buyer[i].p);
v[buyer[i].h] = i;
max = buyer[i].h > max ? buyer[i].h : max;
max2 = buyer[i].p > max2 ? buyer[i].p : max2;
}
for (j = 1; j <= n; j ++)
{
pret = buyer[j].p;
profit = 0;
for (i = 1; i <= max; i ++)
{
if (pret <= buyer[v[i]].p)
profit += pret - c;
else
profit -= c;
if (profit < 0)
profit = 0;
maxim = profit > maxim ? profit : maxim;
}
}
printf("%ld\n", maxim);
return 0;
}