-
Notifications
You must be signed in to change notification settings - Fork 1
/
C.cpp
51 lines (39 loc) · 931 Bytes
/
C.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
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n, ara[200009], cum[200009], cum2[200009];
bool isPos(ll indx)
{
ll lo = indx + 1, hi = n;
//cout << lo << " " << hi << endl;
while(lo <= hi) {
ll mid = (lo + hi) / 2;
//cout << indx << " " << mid << " " << cum2[mid] << endl;
if(cum2[mid] == cum[indx])
return 1;
else if(cum2[mid] > cum[indx])
lo = mid + 1;
else
hi = mid - 1;
}
return 0;
}
int main()
{
cin >> n;
for(ll i = 1; i <= n; i++) {
scanf("%lld", &ara[i]);
cum[i] = ara[i] + cum[i - 1];
}
for(ll i = n; i >= 1; i--)
cum2[i] = ara[i] + cum2[i + 1];
ll ans = 0;
for(ll i = 1; i <= n; i++) {
if(isPos(i) ) {
ans = max(ans, cum[i]);
//cout << ans << endl;
}
}
cout << ans << endl;
return 0;
}