Ankit_132

C

Nov 17th, 2023
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. #define ll long long
  7. #define _test int _TEST; cin>>_TEST; while(_TEST--)
  8.  
  9. int main()
  10. {
  11. _test
  12. {
  13. int n;
  14. cin>>n;
  15.  
  16. vector<ll int> a(n);
  17. for(auto &e: a) cin>>e;
  18.  
  19. ll int ans = -1e18, sum = 0;
  20.  
  21. for(int i=0; i<n; i++)
  22. {
  23. sum += a[i];
  24.  
  25. ans = max(ans, sum);
  26.  
  27. if(i<n && (max(a[i], -a[i]))%2 == (max(a[i+1], -a[i+1]))%2)
  28. sum=0;
  29.  
  30. if(sum < 0) sum = 0;
  31. }
  32.  
  33. cout<<ans<<"\n";
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment