fork download
  1. program menu;
  2. const
  3. MAX=5000;
  4. var
  5. N,B,i,j : integer;
  6. Prezzo:array[1..MAX] of integer;
  7. tab:array[1..MAX,0..MAX] of integer;
  8. preso:array[1..MAX] of boolean;
  9. uscita:boolean;
  10. begin
  11. readln(N,B);
  12. for i:=1 to N do readln(Prezzo[i]);
  13. for i:=1 to N do preso[i]:=false;
  14. for i:=1 to N do
  15. for j:=0 to B do
  16. begin
  17. if j=0 then tab[i,j]:=0
  18. else if j=Prezzo[i] then tab[i,j]:=1
  19. else tab[i,j]:=-1;
  20. end;
  21.  
  22. i:=1;
  23. while (i<N) do
  24. begin
  25. for j:=0 to B do
  26. begin
  27. if tab[i,j]<>-1 then
  28. begin
  29. if j=Prezzo[i] then tab[i+1,j]:=1;
  30. if j+Prezzo[i+1]<=B then tab[i+1, j+Prezzo[i+1]]:=1;
  31. end;
  32.  
  33. end;
  34. i:=i+1;
  35. end;
  36. for i:=1 to N do
  37. begin
  38. for
  39. j:=0 to B do write(tab[i,j],' ');
  40. writeln;
  41. end;
  42. end.
Success #stdin #stdout 0s 5308KB
stdin
3 10
3
7
5
stdout
0 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 
0 -1 -1 1 -1 -1 -1 1 -1 -1 1 
0 -1 -1 -1 -1 1 -1 1 1 -1 -1