Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #include <ext/pb_ds/assoc_container.hpp>
- #include <ext/pb_ds/tree_policy.hpp>
- using namespace std;
- using namespace __gnu_pbds;
- typedef long long ll;
- typedef long double ld;
- typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>Set;
- typedef tree<ll,ll,less<ll>,rb_tree_tag,tree_order_statistics_node_update> Map;
- #define pb push_back
- #define mp make_pair
- #define mod 1000000007
- #define fi first
- #define se second
- #define pll pair<ll,ll>
- #define ook order_of_key
- #define findby find_by_order
- #define pii pair<ll,ll>
- #define gcd(a,b) __gcd(a,b)
- #define rep(i,n) for(ll i=0;i<n;i++)
- #define reps(i,a,b) for(ll i=a;i<=b;i++)
- template<typename X> inline X abs(const X& a) { return (a < 0 ? -a : a); }
- template<typename X> inline X sqr(const X& a) { return (a * a); }
- const ld EPS = ld(1e-9);
- const ld PI = ld(3.141592653589);
- int n;
- int s[100005];
- class Task
- {
- public:
- void solve(istream& in,ostream& out)
- {
- in >> n;
- vector <int> pe,po,ne,no;
- rep(i,n)
- {
- in >> s[i];
- if (s[i] % 2 == 0)
- {
- if (s[i] <= 0)
- {
- ne.pb(s[i]);
- }
- else
- pe.pb(s[i]);
- }
- else
- {
- if (s[i] <= 0)
- no.pb(s[i]);
- else
- po.pb(s[i]);
- }
- }
- int res = -2;
- if (po.size()>0)
- sort(po.begin(),po.end(),greater<int>());
- if (po.size() % 2 == 0 && po.size() != 0)
- {
- res = 0;
- rep(i,po.size()-1)
- {
- res += po[i];
- // out << po[i] << endl;
- }
- }
- else if (po.size() % 2 == 1)
- {
- res = 0;
- rep(i,po.size())
- {
- res+=po[i];
- // out <<po[i] <<" hsgd" << endl;
- }
- }
- if (res == -2)
- {
- res = 0;
- if (no.size()>0){
- sort(no.begin(),no.end());
- res += no[no.size()-1];
- }
- }
- rep(i,pe.size())
- {
- res += pe[i];
- // out <<pe[i] << endl;
- // out << "sdhas" << endl;
- }
- out << res << endl;
- // out << (3 & 1) << endl;
- }
- };
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- Task solver;
- std::istream& in(std::cin);
- std::ostream& out(std::cout);
- solver.solve(in,out);
- out.flush();
- return 0;
- }
Add Comment
Please, Sign In to add comment