fork download
  1. uses math;
  2. const oo=1000000000;
  3. var n,i,j:longint;
  4. max,s:longint;
  5. a: array[1..1000] of longint;
  6. f: array[0..1000] of longint;
  7. begin
  8. readln(n,s);
  9. max:=-oo;
  10. for i:=1 to n do
  11. begin
  12. read(a[i]);
  13. if a[i]>max then max:=a[i];
  14. end;
  15. f[0]:=s div max-1;
  16. s:=s mod max+max;
  17. for i:=1 to s do
  18. begin
  19. f[i]:=oo;
  20. for j:=1 to n do
  21. if a[j]<=i then
  22. if f[i-a[j]]+1<f[i] then f[i]:=f[i-a[j]]+1;
  23. end;
  24. writeln(f[s]);
  25. end.
Success #stdin #stdout 0s 452KB
stdin
2 3
1 2
stdout
2