fork download
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. static const int N = (int)3e5;
  5.  
  6. int n, s;
  7. int a[N];
  8. int p[N];
  9. long long sum;
  10.  
  11. bool comp(const int &x, const int &y) {
  12. return a[x] < a[y];
  13. }
  14.  
  15. int main() {
  16. freopen("input.txt", "rt", stdin);
  17. freopen("output.txt", "wt", stdout);
  18.  
  19. scanf("%d%d", &n, &s);
  20.  
  21. for (int i = 0; i < n; i++) {
  22. scanf("%d", &a[i]);
  23. p[i] = i, sum += a[i];
  24. }
  25.  
  26. std::sort(p, p + n, comp);
  27.  
  28. for (int i = 0; i < n; i++) {
  29. int m = (sum + n - i - 1) / (n - i);
  30.  
  31. if (a[p[i]] + s >= m) {
  32. for (int j = i; j < n; j++)
  33. a[p[j]] = m;
  34.  
  35. break;
  36. }
  37.  
  38. sum -= a[p[i]], a[p[i]] = a[p[i]] + s;
  39. }
  40.  
  41. for (int i = 0; i < n; i++)
  42. printf("%d ", a[i]);
  43.  
  44. return 0;
  45. }
  46.  
Success #stdin #stdout 0s 5812KB
stdin
Standard input is empty
stdout
Standard output is empty