forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
35 lines (28 loc) · 786 Bytes
/
main.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
// Authored by : tony9402
// Co-authored by : -
// Link : http://boj.kr/ba24cf477f634be3b516d7475296bf67
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100000;
ll arr[MAXN + 5], prefix[MAXN + 5];
ll psum(int l, int r) {
return prefix[r] - prefix[l - 1];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
for(int i = 1; i <= N; i++) {
cin >> arr[i];
prefix[i] = prefix[i - 1] + arr[i];
}
ll answer = 0;
for(int i = 2; i < N; i++ ){
answer = max(answer, psum(2, i) + psum(i, N - 1));
answer = max(answer, psum(2, N) + psum(i + 1, N) - arr[i]);
answer = max(answer, psum(1, N - 1) + psum(1, i - 1) - arr[i]);
}
cout << answer;
return 0;
}