Cod sursa(job #2004056)

Utilizator cc4infinityCojocaru Catalin cc4infinity Data 24 iulie 2017 20:05:00
Problema Energii Scor 55
Compilator fpc Status done
Runda Arhiva de probleme Marime 0.97 kb
var i,j,m,n,x,y:longint;
    t:array[0..5001] of longint;
    o:array[1..1000] of record e:longint;
                               c:longint;
                             end;
begin
assign(input,'energii.in');
reset(input);
readln(n);
readln(m);
for i:=1 to n do
readln(o[i].e,o[i].c);
close(input);
for i:=1 to n do
 for j:=m downto 1 do
  begin
   if j-o[i].e>=0 then if (t[j-o[i].e]>0) or (j-o[i].e=0)
                                       then x:=t[j-o[i].e]+o[i].c
                                       else x:=1999999999
                                       else x:=1999999999;
   if (x<t[j]) or((t[j]=0) and (x<>1999999999))  then t[j]:=x
                                                else
                                         if (t[j]>t[j+1]) and(t[j+4]<>0)
                                         or (t[j]=0) then t[j]:=t[j+1];
  end;
assign(output,'energii.out');
rewrite(output);
if t[m]=0 then write(-1) else write(t[m]);
close(output);

end.