-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path1643.cpp
47 lines (35 loc) · 875 Bytes
/
1643.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
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MAXN 200005
int n, ans;
int a[MAXN], sum[MAXN];
// int32_t main() {
// cin.tie(0) -> sync_with_stdio(0);
// cin >> n;
// for (int i = 1; i <= n; i++) {
// cin >> a[i];
// sum[i] = sum[i-1] + a[i];
// }
// int minVal = 0;
// ans = INT_MIN;
// for (int i = 1; i <= n; i++) {
// ans = max(ans, sum[i] - minVal);
// minVal = min(minVal, sum[i]);
// }
// cout << ans;
// return 0;
// }
int32_t main() {
cin.tie(0) -> sync_with_stdio(0);
cin >> n;
int sum = 0;
ans = INT_MIN;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum = max(a[i], sum + a[i]);
ans = max(ans, sum);
}
cout << ans;
return 0;
}