Advertisement
sherry_ahmos

Untitled

Jul 31st, 2022
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <vector>
  4. #include <string>
  5. #include <queue>
  6. #include <map>
  7. #include <set>
  8. #include <string>
  9. #include <algorithm>
  10. #include <cmath>
  11. #include <unordered_map>
  12.  
  13. using namespace std;
  14. #define ll long long
  15. #define nl endl
  16. #define cy cout << "YES\n"
  17. #define cn cout << "NO\n"
  18. #define sz s.size()
  19.  
  20. void sherry()
  21. {
  22.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  23. #ifndef ONLINE_JUDGE
  24.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  25. #endif
  26. }
  27. int main()
  28. {
  29.     sherry();
  30.     ll n, sum = 0, c = 0;
  31.     cin >> n;
  32.     vector<ll> v(0);
  33.     for (int i = 0; i < n; i++)
  34.     {
  35.         ll num;
  36.         cin >> num;
  37.         if (num > 0 && num % 2 == 0)
  38.         {
  39.             sum += num;
  40.         }
  41.         else if (num % 2 != 0)
  42.         {
  43.             v.push_back(num);
  44.             if (num > 0)
  45.             {
  46.                 c++;
  47.             }
  48.         }
  49.     }
  50.     sort(v.begin(), v.end(), greater<ll>());
  51.     if (c % 2 == 0)
  52.     {
  53.         c--;
  54.     }
  55.     for (int i = 0; i < v.size(); i++)
  56.     {
  57.         sum += v[i];
  58.         c--;
  59.         if (c <= 0)
  60.         {
  61.             break;
  62.         }
  63.     }
  64.     cout << sum;
  65. }
  66.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement