fork download
  1. var c,n,i,w,j,max,p:longint;
  2. t: array[0..500] of longint;
  3. function notfound(x:longint):boolean;
  4. var i:longint;
  5. begin
  6. for i:=1 to t[0] do
  7. if t[i]=x then
  8. begin
  9. notfound:=false;
  10. exit;
  11. end;
  12. notfound:=true;
  13. end;
  14. begin
  15. readln(c,n);
  16. t[0]:=0;
  17. max:=0;
  18. for i:=1 to n do
  19. begin
  20. readln(w);
  21. if (w<=c) then
  22. begin
  23. for j:=1 to t[0] do
  24. begin
  25. p:=t[j]+w;
  26. if (notfound(p)) and (p<=c) then
  27. begin
  28. inc(t[0]);
  29. t[t[0]]:=p;
  30. if p>max then max:=p;
  31. end;
  32. end;
  33. if notfound(w) then
  34. begin
  35. inc(t[0]);
  36. t[t[0]]:=w;
  37. if w>max then max:=w;
  38. end;
  39. end;
  40. end;
  41. writeln(max);
  42. end.
Success #stdin #stdout 0s 280KB
stdin
Standard input is empty
stdout
0