Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define INF 1<<30
  4. #define MAX 10005
  5. #define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  6. typedef long long ll;
  7.  
  8.  
  9. int main()
  10. {
  11. FASTIO
  12. ///*
  13. //double start_time = clock();
  14. #ifndef ONLINE_JUDGE
  15. freopen("in.txt", "r", stdin);
  16. freopen("out.txt", "w", stdout);
  17. freopen("error.txt", "w", stderr);
  18. #endif
  19. //*/
  20.  
  21. int n;
  22. cin >> n;
  23. int mn = 100000000, mx = -100000000, sum = 0;
  24. for(int i = 0; i < n; i++){
  25. int x;
  26. cin >> x;
  27. if(x > 0){
  28. sum += x;
  29. if(x%2 == 1 && x < mn){
  30. mn = x;// small positive odd integer.
  31. }
  32. }
  33. else if(x < 0){
  34. if(abs(x)%2 == 1 && x > mx){
  35. mx = x; //Big Negeative odd integer.
  36. }
  37. }
  38. }
  39.  
  40. if(sum%2 == 0){
  41. sum = max(sum-mn, sum+mx);
  42. }
  43. cout << sum << endl;
  44.  
  45. //double end_time = clock();
  46. //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement