Cod sursa(job #28825)

Utilizator adrianraduleaRadulea Adrian adrianradulea Data 8 martie 2007 12:34:53
Problema Energii Scor 25
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.76 kb
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.