Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <vector>
- #include <string>
- #include <queue>
- #include <map>
- #include <set>
- #include <string>
- #include <algorithm>
- #include <cmath>
- #include <unordered_map>
- using namespace std;
- #define ll long long
- #define nl endl
- #define cy cout << "YES\n"
- #define cn cout << "NO\n"
- #define sz s.size()
- void sherry()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- int main()
- {
- sherry();
- ll n, sum = 0, c = 0;
- cin >> n;
- vector<ll> v(0);
- for (int i = 0; i < n; i++)
- {
- ll num;
- cin >> num;
- if (num > 0 && num % 2 == 0)
- {
- sum += num;
- }
- else if (num % 2 != 0)
- {
- v.push_back(num);
- if (num > 0)
- {
- c++;
- }
- }
- }
- sort(v.begin(), v.end(), greater<ll>());
- if (c % 2 == 0)
- {
- c--;
- }
- for (int i = 0; i < v.size(); i++)
- {
- sum += v[i];
- c--;
- if (c <= 0)
- {
- break;
- }
- }
- cout << sum;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement