-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Flip_Flop_Sum.cpp
More file actions
54 lines (50 loc) · 1.15 KB
/
B_Flip_Flop_Sum.cpp
File metadata and controls
54 lines (50 loc) · 1.15 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100000005;
vector<bool> p(MAXN, false);
// vector<ll> dp;
vector<ll> seg;
vector<ll> arr;
#define fastio \
{ \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
}
int main()
{
ll t;
cin >> t;
while (t--)
{
ll n;
cin >> n;
ll arr[n + 1];
ll sum = 0;
for (ll i = 0; i < n; i++)
{
cin >> arr[i];
sum += arr[i];
// sum++;
}
ll c = 0, d = 0;
for (ll i = 0; i < n - 1; i++)
{
if (arr[i] == -1 && arr[i + 1] == -1)
{
c = 1;
d = 0;
break;
}
else if ((arr[i] == -1 || arr[i + 1] == -1) && d == 0 && c == 0)
d = 1;
// sum += arr[i] + arr[i + 1];
}
if (d == 1)
cout << sum << endl;
else if (c == 1)
cout << sum + 4 << endl;
else
cout << sum - 4 << endl;
}
}