Pagini recente » Cod sursa (job #1434663) | Cod sursa (job #1784709) | Cod sursa (job #1583502) | Cod sursa (job #3182947) | Cod sursa (job #28825)
Cod sursa(job #28825)
var G,i,j:longint;
W:longint;
f,h:text;
x:longint;
min:longint;
a:array[1..2,1..10001] of integer;
cost,s:longint;
ok:boolean;
begin
assign(f,'energii.in'); reset(f);
assign(h,'energii.out'); rewrite(h);
readln(f,G);
readln(f,W);
min:=250000000;
s:=0;
for i:=1 to G do begin
read(f,a[1,i],a[2,i]);
s:=s+a[1,i];
end;
for i:=1 to G-1 do
for j:=i+1 to G do
if (a[1,i]/a[2,i])<(a[1,j]/a[2,j]) then begin
x:=a[1,i];
a[1,i]:=a[1,j];
a[1,j]:=x;
x:=a[2,i];
a[2,i]:=a[2,j];
a[2,j]:=x;
end;
if s>=W then begin
i:=1;
cost:=0;
Repeat
cost:=cost+a[2,i];
w:=w-a[1,i];
i:=i+1;
until w<=0;
write(h,cost);
end
else write(h,'-1');
close(h);
end.