forked from anandadfoxx/codeforces_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1343C.cpp
More file actions
43 lines (38 loc) · 901 Bytes
/
Copy path1343C.cpp
File metadata and controls
43 lines (38 loc) · 901 Bytes
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
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
LL sum = 0, temp = 0;
bool negative_flag = false;
FOR(i, 0, n) {
LL x;
cin >> x;
if (i == 0) temp = x;
else if (x < 0) {
if (temp > 0) {
sum += temp;
temp = x;
}
temp = max(temp, x);
}
else if (x > 0) {
if (temp < 0) {
sum += temp;
temp = x;
}
temp = max(temp, x);
}
}
if (temp != 0) {
sum += temp;
temp = 0;
}
cout << sum << '\n';
}
}