Cod sursa(job #198332)

Utilizator kis_lorikis levente lorand kis_lori Data 10 iulie 2008 13:50:17
Problema Energii Scor 85
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.58 kb
var g,w,i,j:longint;
    e,c: longint;
    v:array [1..100000] of longint;
begin
 assign(input,'energii.in'); reset(input);
 assign(output,'energii.out'); rewrite(output);
  readln(g); readln(w);
  for i:=1 to g do begin
    readln(e,c);
    for j:=w downto 1 do
      if v[j]<>0 then begin
        if v[j+e]=0 then v[j+e]:=c+v[j]
        else
          if v[j+e]>c+v[j] then v[j+e]:=c+v[j];
      end;
    if (v[e]=0) or (v[e]>c) then v[e]:=c;
  end;
 j:=w;
 for i:=w to 100000 do
   if (v[i]<v[j])and(v[i]>0) then j:=i;
 write(v[j]);
 close(input); close(output);
end.