-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_First_or_Second.cpp
More file actions
46 lines (37 loc) · 825 Bytes
/
C_First_or_Second.cpp
File metadata and controls
46 lines (37 loc) · 825 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
44
45
46
#include <bits/stdc++.h>
using namespace std;
// First you make it work, then you can always make it beautiful
#define int long long
const int inf = 1e18;
void solve() {
int n;
cin >> n;
vector<int> v(n+1), pre(n + 1), suff(n + 2);
for(int i=1;i<=n;i++) {
cin >> v[i];
}
for(int i=2;i<=n;i++) {
pre[i] = pre[i-1];
if(v[i] > 0) pre[i] += v[i];
else pre[i] -= v[i];
}
for(int i=n;i>0;i--) {
suff[i] = suff[i+1] + v[i];
}
int ans = -suff[2];
for(int i=2;i<=n;i++) {
ans = max(ans, v[1] + pre[i-1] - suff[i+1]);
}
cout << ans << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int _;
cin >> _;
while (_-->0) {
solve();
}
return 0;
}