cf地址
**题目大意:**一个序列,你可以选择一个子段,要求去掉子段最大值后的和最大,求出这个最大值
**思路:**a[i]的范围比较小,可以通过枚举最大值,再找到最大值可以辐射的区间。经典套路了。
代码:
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#define INF 0x3f3f3f3f3f3f3f3f
#define inf 0x3f3f3f3f
#define FILL(a,b) (memset(a,b,sizeof(a)))
#define re register
#define lson rt<<1
#define rson rt<<1|1
#define lowbit(a) ((a)&-(a))
#define ios std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
#define fi first
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define se secondusing namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int > pii;
const ll mod=10001;
const ll N =2e5+10;
const double eps = 1e-4;
const double pi=acos(-1);
ll gcd(int a,int b){return !b?a:gcd(b,a%b);}
int dx[4]={-1,0,1,0} , dy[4] = {0,1,0,-1};
int a[N];void solve()
{int n;cin>>n;rep1(i,n) cin>>a[i];int any=0;for(int i=1;i<=30;i++){int cnt=0;int x=0;for(int j=1;j<=n;j++){if(a[j]>i){cnt=0;x=0;continue;}if(a[j]==i) x=1;cnt+=a[j];if(cnt<0){cnt=0;x=0;continue;}if(x) any=max(any,cnt-i);}}cout<<any;
}int main()
{iosint T;T=1;while(T--){solve();}return 0;
}