Cod sursa(job #733062)

Utilizator MaarcellKurt Godel Maarcell Data 11 aprilie 2012 13:22:12
Problema Energii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.77 kb
type gener=record
 x,y:longint;
end;
var i,j,k,l,m,n:longint; f1,f2:text; a:array[1..1001] of gener;
b:boolean;
begin
assign(f1,'energii.in');
reset(f1);
assign(f2,'energii.out');
rewrite(f2);
readln(f1,n);
readln(f1,m);
for i:=1 to n do
readln(f1,a[i].x,a[i].y);
repeat
b:=true;
for i:=1 to n-1 do
if a[i].x<a[i+1].x then begin
k:=a[i].x;
l:=a[i].y;
a[i].x:=a[i+1].x;
a[i].y:=a[i+1].y;
a[i+1].x:=k;
a[i+1].y:=l;
b:=false;
end;
until b;
repeat
b:=true;
for i:=1 to n-1 do
if (a[i].y>a[i+1].y) and (a[i].x=a[i+1].x) then begin
k:=a[i].x;
l:=a[i].y;
a[i].y:=a[i+1].y;
a[i].x:=a[i+1].x;
a[i+1].x:=k;
a[i+1].y:=l;
b:=false;
end;
until b;
i:=1;
l:=0;
k:=0;
repeat
l:=l+a[i].x;
k:=k+a[i].y;
until l>=m;
writeln(f2,k);
close(f1);
close(f2);
end.