SlepoiKrot

Untitled

Dec 31st, 2017
115
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. program sweets;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. SysUtils;
  7. var
  8. n, m, min, i, k: integer;
  9. a: array [1..10001] of integer;
  10. begin
  11. readln (n, m);
  12. min := n + 1;
  13. k := 1;
  14. for i := 1 to n do begin
  15. readln (a[i]);
  16. end;
  17. while (m <> 0) do begin
  18. a[min] := 30001;
  19. for i := 1 to n do begin
  20. if (a[i] < a[min]) then
  21. min := i
  22. else if (a[i] = a[min]) then
  23. inc (k);
  24. end;
  25. if (k = n) and (m > n) then begin
  26. for i := 1 to n do begin
  27. a[i] := a[i] + m div n;
  28. end;
  29. k := 1;
  30. m := m mod n;
  31. min := n + 1;
  32. continue;
  33. end;
  34. k := 1;
  35. m := m - 1;
  36. inc (a[min]);
  37. min := n + 1;
  38. end;
  39. min := 1000000;
  40. for i := 1 to n do begin
  41. if (a[i] < min) then
  42. min := a[i];
  43. end;
  44. writeln (min);
  45. readln;
  46. readln;
  47. end.
RAW Paste Data