Pagini recente » Cod sursa (job #1336374) | Cod sursa (job #1799766) | Cod sursa (job #1080135) | Cod sursa (job #1239445) | Cod sursa (job #161836)
Cod sursa(job #161836)
program p1;
type tip=0..1000000000;
var a,b:array[1..100] of integer;
f1,f2:text;
n,j,i,l,m:longint;
k,aux,max:tip;
ok:boolean;
begin
assign(f1,'carnati.in');
reset(f1);
readln(f1,n,k);
for i:=1 to n do
readln(f1,a[i],b[i]);
close(f1);
repeat
ok:=true;
for i:=1 to n-1 do
begin
if a[i]>a[i+1] then
begin
ok:=false;
aux:=a[i];
a[i]:=a[i+1];
a[i+1]:=aux;
aux:=b[i];
b[i]:=b[i+1];
b[i+1]:=aux;
end;
end;
until ok=true;
for i:=1 to n do
for j:=1 to n do
for l:=j to n do
begin
aux:=0;
for m:=j to l do
if b[i]<=b[m] then
aux:=aux+b[i];
aux:=aux-k*(a[l]-a[j]+1);
if aux>max then
max:=aux;
end;
assign(f2,'carnati.out');
rewrite(f2);
writeln(f2,max);
close(f2);
end.