fork(2) download
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. const int MAXN = 5020;
  7.  
  8. int a[MAXN];
  9. bool f[MAXN];
  10.  
  11. int main()
  12. {
  13. // freopen("input.txt", "r", stdin);
  14. freopen("round.in", "r", stdin);
  15. //freopen("output.txt", "w", stdout);
  16. freopen("round.out", "w", stdout);
  17. int n, m;
  18. cin >> n >> m;
  19. int s = 0;
  20. for (int i = 0; i < n; ++i) {
  21. cin >> a[i];
  22. s += a[i];
  23. }
  24. int sum = 0;
  25. for (int i = 0; i < n; ++i) {
  26. // cout << fixed << (double) a[i] / s * m << ' ';
  27. if (a[i] % s == 0)
  28. f[i] = 1;
  29.  
  30. a[i] = ceil((double) a[i] / s * m);
  31. sum += a[i];
  32. }
  33. // cout << endl;
  34. // for (int i = 0; i < n; ++i)
  35. // cout << a[i] << ' ';
  36. // cout << endl;
  37. int i = 0;
  38. while (sum != m) {
  39. if (!f[i]) {
  40. a[i] -= 1;
  41. sum -= 1;
  42. }
  43. ++i;
  44. }
  45. for (i = 0; i < n; ++i)
  46. cout << a[i] << ' ';
  47. }
  48.  
Runtime error #stdin #stdout 0s 3488KB
stdin
Standard input is empty
stdout
Standard output is empty