fork download
  1. #include <bits/stdc++.h>
  2. #define pb push_back
  3. #define er erase
  4. #define in insert
  5. #define s(a, x, y) sort(a.begin()+x, a.begin()+y);
  6. #define r(a, x, y) reverse(a.begin()+x, a.begin()+y);
  7. #define mp make_pair
  8. #define F first
  9. #define S second
  10. #define ll long long
  11. #define ld long double
  12. #define forn(i, a, b) for(int i=a; i<=b; i++)
  13. #define form(i, a, b) for(int i=a; i>=b; i--)
  14. #define PI 3.14159265358979
  15. #define inf 2147483647
  16. #define sp setprecision
  17. using namespace std;
  18. ll n, w, a[102], b[102];
  19. vector<pair<pair<int, int>, int>> v;
  20. int main() {
  21. ios_base::sync_with_stdio(false);
  22. cin.tie(NULL);
  23. cout.tie(NULL);
  24. cin>>n>>w;
  25. forn(i, 0, n-1){
  26. cin>>a[i];
  27. b[i]=(a[i]+1)/2;
  28. w-=b[i];
  29. v.pb(mp(mp(b[i], -a[i]), i));
  30. }
  31. if(w<0){
  32. cout<<-1;
  33. return 0;
  34. }
  35. while(w>0){
  36. s(v, 0, n);
  37. v[0].F.F++;
  38. b[v[0].S]++;
  39. w--;
  40. }
  41. forn(i, 0, n-1) cout<<b[i]<<" ";
  42. return 0;
  43. }
Success #stdin #stdout 0s 4552KB
stdin
1 9
11
stdout
9