Pagini recente » Cod sursa (job #757005) | Cod sursa (job #162322) | Cod sursa (job #43757) | Cod sursa (job #248250) | Cod sursa (job #28525)
Cod sursa(job #28525)
var G,i,j:integer;
W:integer;
f,h:text;
x:integer;
min:longint;
a:array[1..2,1..1001] of integer;
cost:longint;
ok:boolean;
begin
assign(f,'energii.in'); reset(f);
assign(h,'energii.out'); rewrite(h);
readln(f,G);
readln(f,W);
min:=10000;
for i:=1 to G do read(f,a[1,i],a[2,i]);
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;
i:=1;
cost:=0;
Repeat
if a[1,i]<=W then begin
cost:=cost+a[2,i];
W:=W-a[1,i];
end;
i:=i+1;
until w<=0;
write(h,cost);
close(h);
end.