-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1903C.cpp
52 lines (42 loc) · 985 Bytes
/
1903C.cpp
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
/*
RunAt - grey
*/
#include <iostream>
#include <set>
#include <map>
#include <climits>
#include <string>
#include <numeric>
#include <algorithm>
#include <vector>
using namespace std;
typedef int long long ll;
#define printnl(a) cout << a << "\n";
#define printab(a,b) cout << a << " " << b << "\n";
#define readV(vec) for (auto &e: vec) cin >> e;
#define debugV(vec) for (auto &e: vec) {cout << e << " ";} cout << "\n";
#define YES cout << "YES" << "\n"
#define NO cout << "NO" << "\n"
const int N = 100005;
void solve() {
ll n;
cin >> n;
vector<ll> arr(n);
readV(arr);
ll maxSum = 0;
ll curr = 0;
for (int i=n-1; i>0; i--) {
curr += arr[i];
if (curr > 0) maxSum += curr;
}
// If by the end of the loop, curr is still negative
// We will get some value in maxSum
maxSum += arr[0] + curr;
printnl(maxSum);
}
int main() {
int tests = 1;
cin >> tests;
while (tests--) solve();
return 0;
}