Mai intai trebuie sa te autentifici.
Cod sursa(job #332820)
| Utilizator | Data | 20 iulie 2009 11:05:05 | |
|---|---|---|---|
| Problema | Carnati | Scor | 10 |
| Compilator | fpc | Status | done |
| Runda | Arhiva de probleme | Marime | 0.77 kb |
var t,p:array[1..2000] of longint;
n,c,i,max,m,b2,pmax,pmax2,x:longint;
f,g:text;
function val(pr:longint):word;
begin
if pr>=x then
val:=1
else
val:=0;
end;
begin
assign(f,'carnati.in');
assign(g,'carnati.out');
reset(f);rewrite(g);
readln(f,n,c);
for i:=1 to n do
readln(f,t[i],p[i]);
pmax2:=-maxlongint;
for m:=1 to n do
begin
x:=p[m];
pmax:=val(p[1])*x-c;
b2:=pmax;
for i:=2 to n do
begin
if b2>=0 then
b2:=b2+val(p[i])*x+t[i-1]*c-t[i]*c
else
b2:=val(p[i])*x-c;
if b2>pmax then
pmax:=b2;
end;
if pmax>pmax2 then
pmax2:=pmax;
end;
write(g,pmax2);
close(f);close(g);
end.