D - Yet Another Yet Another Task

题目链接

题目大意

让你从一段区间里删除一个最大值,求他们的和。
问这个和的最大值是多少。
n是1e5.
但是数组里数字的大小只有 -30~30

题解

求一段区间删除最大值后的和。
可以枚举一个数,假设这个数是删除的数
然后求
这个数的前面连续的小于等于这个数的和的最大值

这个数后面的连续的小于等于这个数的和的最大值
这怎么求?
dpl[i][j] 表示第i个以及第i个左边小于等于j的数的和的最大值。
dpr同理
然后从左到右处理一遍,从右到左处理一遍就好了
怎么处理? 假设这个值是a[i] 然后在他后面比a[i]大的值都可以加上这个a[i]。
a[i]只有三十。可以遍历一下
代码

#include<iostream>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <cstring>
#include <string>
#include <bitset>
#include <stdlib.h>
#include <time.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define st first
#define sd second
#define mkp make_pair
#define pb push_back
void wenjian(){
   freopen("xxx.in","r",stdin);freopen("xxx.out","w",stdout);}
void tempwj(){
   freopen("hash.in","r",stdin);freopen("hash.out","w",stdout);}
ll gcd(ll a,ll b){
   return b == 0 ? a : gcd(b,a % b);}
ll qpow(ll a,ll b,ll mod){
   a %= mod;ll ans = 1;while(b){
   if(b & 1)ans = ans * a % mod;a = a * a % mod;b >>= 1;}return ans;}
struct cmp{
   bool operator()(const pii & a, const pii & b){
   return a.second > b.second;}};
int lb(int x){
   return  x & -x;}

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9+9;
const int maxn = 2e5+5;
int dpl[maxn][65];
int dpr[maxn][65];
int a[maxn];
int main()
{
   
	int n;
	scanf("%d",&n);
	for (int i = 1; i <= n; i ++ )
	{
   
		scanf("%d",&a[i]);
	}
	for (int i = 1; i <= n; i ++ )
	{
   
		int x = a[i] + 30;
		for (int j = x; j <= 60; j ++ )
		{
   
			dpl[i][j] = max(0,dpl[i - 1][j] + a[i]);
		}
	}
	for (int  i= n; i >= 1; i -- )
	{
   
		int x = a[i] + 30;
		for (int j = x; j <= 60; j ++ )
		{
   
			dpr[i][j] = max(0,dpr[i + 1][j] + a[i]);
		}
	}
	int ans = 0;
	for (int i = n; i >= 1; i -- )
	{
   
		int x = a[i] + 30;
		ans = max(ans,dpl[i - 1][x] + dpr[i + 1][x]);
	}
	printf("%d\n",ans);
}