Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using LL = long long int;
  5.  
  6. template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
  7. template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  8.   while(*sdbg!=',')
  9.     cerr<<*sdbg++;
  10.   cerr<<"="<<h<<",";
  11.   _dbg(sdbg+1, a...);
  12. }
  13.  
  14. template<class T> ostream & operator<<(ostream & os, vector<T> V){
  15.   os<<"[";
  16.   for(auto vv: V) os << vv <<",";
  17.   return os << "]";
  18. }
  19. template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  20.   return os <<"("<<P.st <<","<<P.nd <<")";
  21. }
  22.  
  23. #ifdef DEBUG
  24. #define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
  25. #else
  26. #define debug(...) (__VA_ARGS__)
  27. #define cerr if(0)cout
  28. #endif
  29.  
  30. int ans[100000];
  31.  
  32. int main() {
  33.   int n;
  34.   cin >> n;
  35.   vector<pair<int,int>> w0, m0, v;
  36.   for (int i = 1; i <= n; ++i) {
  37.     int x;
  38.     cin >> x;
  39.     v.push_back({x / 2, x % 2});
  40.   }
  41.  
  42.   int sum = 0;
  43.   for (auto x : v) {
  44.     sum += x.first;
  45.   }
  46.  
  47.   if (sum == 0) {
  48.     for (auto x : v) {
  49.       cout << x.first << endl;
  50.     }
  51.     return 0;
  52.   }
  53.  
  54.  
  55.   debug(sum);
  56.   for (int i = 0; i < (int)v.size(); ++i) {
  57.     if (v[i].second == 0) {
  58.       continue;
  59.     }
  60.  
  61.     if (sum < 0 && v[i].first >= 0) {
  62.       v[i].first++;
  63.       sum++;
  64.     } else if (sum > 0 && v[i].first <= 0) {
  65.       v[i].first--;
  66.       sum--;
  67.     }
  68.   }
  69.  
  70.   int ss = 0;
  71.   for (auto x : v) {
  72.     ss += x.first;
  73.         cout << x.first << endl;
  74.       }
  75.       assert(ss == 0);
  76.       return 0;  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement