-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.cpp
More file actions
79 lines (69 loc) · 1.94 KB
/
Copy pathtempCodeRunnerFile.cpp
File metadata and controls
79 lines (69 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i, a, b) for (int i = a; i < b; i++)
void solve() {
}
int main() {
fastio;
int t;
cin >> t;
while (t--) {
int n;
cin>>n;
vector<pair<int , char>> arr(n);
for(int i=0;i<n;i++){
cin>>arr[i].first;
if(arr[i].first%2!=0) arr[i].second = 'O';
else arr[i].second = 'E';
// cout<<arr[i].second<<endl;
}
int l = 0 , r = 0;
int sum = arr[0].first ;
int ori = arr[0].first;
// cout<<ori<<endl;
// cout<<"run ";
while(l<n){
ori = max(ori , sum);
if(r+1<n && arr[r].second != arr[r+1].second){
r++;
sum+=arr[r].first;
// cout<<"run 1 ";
}
else if(r<n && l<r){
// cout<<"run 3 ";
int temp = sum;
for(int i = r;i>=l;i--){
int temp2 = temp;
//cout<<"running till "<<i<<" ";
for(int x = l;x<=i;x++){
//cout<<"from "<<x<<" ";
temp2-=arr[x].first;
ori = max(ori , temp2);
}
temp-=arr[i].first;
//cout<<endl;
}
r++;
l = r;
//cout<<l<<endl;
ori = max(arr[l].first , ori);
}
else if(l==r && r+1<n){
r++;
l = r;
sum = arr[l].first;
//cout<<"run 3 ";
}
else break;
ori = max(ori , sum);
// cout<<"original "<<ori<<endl;
}
cout<<ori<<endl;
}
return 0;
}