rakcode1998

Untitled

Apr 15th, 2017
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6.  
  7. typedef long long ll;
  8. typedef long double ld;
  9. typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>Set;
  10. typedef tree<ll,ll,less<ll>,rb_tree_tag,tree_order_statistics_node_update> Map;
  11.  
  12. #define pb push_back
  13. #define mp make_pair
  14. #define mod 1000000007
  15. #define fi first
  16. #define se second
  17. #define pll pair<ll,ll>
  18. #define ook order_of_key
  19. #define findby find_by_order
  20. #define pii pair<ll,ll>
  21. #define gcd(a,b) __gcd(a,b)
  22. #define rep(i,n) for(ll i=0;i<n;i++)
  23. #define reps(i,a,b) for(ll i=a;i<=b;i++)
  24.  
  25. template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
  26. template<typename X> inline X sqr(const X& a) { return (a * a); }
  27.  
  28. const ld EPS = ld(1e-9);
  29. const ld PI = ld(3.141592653589);
  30.  
  31. int n;
  32. int s[100005];
  33.  
  34. class Task
  35. {
  36. public:
  37.      void solve(istream& in,ostream& out)
  38.      {
  39.           in >> n;
  40.  
  41.           vector <int> pe,po,ne,no;
  42.  
  43.           rep(i,n)
  44.           {
  45.                 in >> s[i];
  46.                 if (s[i] % 2 == 0)
  47.                 {
  48.                      if (s[i] <= 0)
  49.                      {
  50.                           ne.pb(s[i]);
  51.                      }
  52.                      else
  53.                      pe.pb(s[i]);
  54.                 }
  55.                 else
  56.                 {
  57.                      if (s[i] <= 0)
  58.                      no.pb(s[i]);
  59.                      else
  60.                      po.pb(s[i]);
  61.                 }
  62.           }
  63.  
  64.           int res = -2;
  65.           if (po.size()>0)
  66.           sort(po.begin(),po.end(),greater<int>());
  67.  
  68.           if (po.size() % 2 == 0 && po.size() != 0)
  69.           {
  70.                 res = 0;
  71.                 rep(i,po.size()-1)
  72.                 {
  73.                      res += po[i];
  74.               //       out << po[i] << endl;
  75.                 }
  76.           }
  77.           else if (po.size() % 2 == 1)
  78.           {
  79.                 res = 0;
  80.                 rep(i,po.size())
  81.                 {
  82.                      res+=po[i];
  83.            //          out <<po[i] <<" hsgd" << endl;
  84.                 }
  85.           }
  86.  
  87.           if (res == -2)
  88.           {
  89.                 res = 0;
  90.  
  91.                 if (no.size()>0){
  92.                      sort(no.begin(),no.end());
  93.  
  94.                      res += no[no.size()-1];
  95.                 }
  96.           }
  97.  
  98.           rep(i,pe.size())
  99.           {
  100.                 res += pe[i];
  101.      //           out <<pe[i] << endl;
  102.     //            out << "sdhas" << endl;
  103.           }
  104.  
  105.           out << res << endl;
  106.  
  107.     //      out << (3 & 1) << endl;
  108.      }
  109. };
  110.  
  111.  
  112. int main()
  113. {
  114.     ios_base::sync_with_stdio(false);
  115.     cin.tie(NULL);
  116.     cout.tie(NULL);
  117.     Task solver;
  118.     std::istream& in(std::cin);
  119.     std::ostream& out(std::cout);
  120.     solver.solve(in,out);
  121.     out.flush();
  122.  
  123.     return 0;
  124. }
Add Comment
Please, Sign In to add comment