-
Notifications
You must be signed in to change notification settings - Fork 0
/
1007.cpp
34 lines (33 loc) · 709 Bytes
/
1007.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
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10001;
int seq[MAXN], dpsum[MAXN] = {-0x3fffffff}, dpi[MAXN] , n;
int main(){
ios::sync_with_stdio(false);
bool positiveFlag = false;
cin>>n;
for(int i=1; i<=n; i++){
cin>>seq[i];
if(seq[i] >= 0) positiveFlag = true;
if(dpsum[i-1]+seq[i] < seq[i]){
dpsum[i] = seq[i];
dpi[i] = i;
}else{
dpsum[i] = dpsum[i-1] + seq[i];
dpi[i] = dpi[i-1];
}
}
int maxsum = INT_MIN, maxidx = 1;
for(int i=1; i<=n; i++){
if(dpsum[i] > maxsum){
maxsum = dpsum[i];
maxidx = i;
}
}
if(positiveFlag == false){
cout<<0<<' '<<seq[1]<<' '<<seq[n];
}else{
cout<<maxsum<<' '<<seq[dpi[maxidx]]<<' '<<seq[maxidx];
}
return 0;
}