-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode1006C.cpp
More file actions
45 lines (36 loc) · 712 Bytes
/
Copy pathcode1006C.cpp
File metadata and controls
45 lines (36 loc) · 712 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
/*
* Contest : Codeforces
* Problem : 1006C - Three Parts of the Array
* Link : https://codeforces.com/problemset/problem/1006/C
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int main() {
fastio
ll n; cin >> n;
ll d[n];
for (auto &e : d) cin >> e;
ll l = 0, r = n - 1, ans = 0;
ll sum1 = d[l], sum3 = d[r];
while (l < r) {
if (sum1 == sum3 && l < r) {
ans = max(ans, sum1);
l++;
sum1 += d[l];
r--;
sum3 += d[r];
}
else if (sum1 < sum3) {
l++;
sum1 += d[l];
}
else {
r--;
sum3 += d[r];
}
}
cout << ans << "\n";
return 0;
}