Nu aveti permisiuni pentru a descarca fisierul grader_test23.in
Cod sursa(job #137230)
Utilizator | Data | 17 februarie 2008 10:27:42 | |
---|---|---|---|
Problema | Carnati | Scor | 20 |
Compilator | cpp | Status | done |
Runda | preONI 2008, Runda 4, Clasa a 10-a | Marime | 0.81 kb |
#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);
}
for (i = 1; i <= n; i ++)
{
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;
}