fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int MAXN = 5020;
  6.  
  7. int a[MAXN];
  8.  
  9. int main()
  10. {
  11. int n, m;
  12. cin >> n >> m;
  13. double s = 0;
  14. for (int i = 0; i < n; ++i) {
  15. cin >> a[i];
  16. s += a[i];
  17. }
  18. int sum = 0;
  19. for (int i = 0; i < n; ++i) {
  20. a[i] = ceil(a[i] / s * m);
  21. sum += a[i];
  22. }
  23. int i = 0;
  24. while (sum != m) {
  25. a[i] -= 1;
  26. sum -= 1;
  27. ++i;
  28. }
  29. for (int i = 0; i < n; ++i)
  30. cout << a[i] << ' ';
  31. }
  32.  
Success #stdin #stdout 0s 3492KB
stdin
3 10
50 1 49
stdout
4 1 5