Problem - D - Codeforces
思路:我们先将输入数据做一个前缀和,能够得到它的变化,然后我们能够发现我们只需要找到两个点,第一个点-第二个点最大即可,因为假如说我们现在到了一峰
// Problem: D. Rating System
// Contest: Codeforces - Educational Codeforces Round 151 (Rated for Div. 2)
// URL: https://codeforces.com/problemset/problem/1845/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms#include<iostream>
#include<cstring>
#include<string>
#include<sstream>
#include<bitset>
#include<deque>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<vector>
#include<set>
#include<unordered_map>
#include<ctime>
#include<cstdlib>
#define fi first
#define se second
#define i128 __int128
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> PII;
typedef pair<int,pair<int,int> > PIII;
const double eps=1e-7;
const int N=5e5+7 ,M=5e5+7, INF=0x3f3f3f3f,mod=1e9+7,mod1=998244353;
const long long int llINF=0x3f3f3f3f3f3f3f3f;
inline ll read() {ll x=0,f=1;char c=getchar();while(c<'0'||c>'9') {if(c=='-') f=-1;c=getchar();}
while(c>='0'&&c<='9') {x=(ll)x*10+c-'0';c=getchar();} return x*f;}
inline void write(ll x) {if(x < 0) {putchar('-'); x = -x;}if(x >= 10) write(x / 10);putchar(x % 10 + '0');}
inline void write(ll x,char ch) {write(x);putchar(ch);}
void stin() {freopen("in_put.txt","r",stdin);freopen("my_out_put.txt","w",stdout);}
bool cmp0(int a,int b) {return a>b;}
template<typename T> T gcd(T a,T b) {return b==0?a:gcd(b,a%b);}
template<typename T> T lcm(T a,T b) {return a*b/gcd(a,b);}
void hack() {printf("\n----------------------------------\n");}int T,hackT;
int n,m,k;
ll w[N];void solve() {n=read();for(int i=1;i<=n;i++) w[i]=read();for(int i=2;i<=n;i++) w[i]+=w[i-1];ll res=0;ll maxn=0;ll last=0-w[1];for(int i=1;i<=n;i++) {ll t=maxn-w[i];if(t>last) {last=t;res=maxn;}maxn=max(maxn,w[i]);}printf("%lld\n",res);
} int main() {// init();// stin();scanf("%d",&T);// T=1; while(T--) hackT++,solve();return 0;
}