Cod sursa(job #559624)

Utilizator GhitaRaulGhita Raul GhitaRaul Data 17 martie 2011 22:30:46
Problema Energii Scor 0
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.77 kb
Program energii;
type sir=record
     c,e:integer;
     p:real;
     end;
var v:array[1..30]of sir;
    aux:sir;
    i,g,w,cost:integer;
    f,f1:text;
    ok:boolean;
begin
ok:=true;
cost:=0;
assign(f,'energii.in');reset(f);
assign(f1,'energii.out');rewrite(f1);
readln(f,g,w);
For i:=1 to g do begin
read(f,v[i].e,v[i].c);
v[i].p:=v[i].c/v[i].e;
end;
While not ok do begin
ok:=true;
For i:=1 to g-1 do
If v[i].p>v[i+1].p then
begin
aux:=v[i];
v[i]:=v[i+1];
v[i+1]:=aux;
ok:=false;
end;
end;
i:=1;
ok:=false;
 While (not ok)and(i<=g) do begin
 If v[i].e>=w then
  begin
   cost:=cost+v[i].c;
   ok:=true;
  end
              else
  begin
   w:=w-v[i].e;
   cost:=cost+v[i].c;
  end;
 inc(i);
 end;
writeln(f1,cost);
close(f1);
end.