比赛 EYOI暨SBOI暑假快乐赛6th 评测结果 AAAAAAAAAA
题目名称 Count 1s 最终得分 100
用户昵称 遥时_彼方 运行时间 0.021 s
代码语言 C++ 内存使用 1.60 MiB
提交时间 2022-06-30 09:25:07
显示代码纯文本
#include<bits/stdc++.h>
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define drep(x,y,z) for(int x=y;x>=z;x--)
#define ull unsigned long long
#define ll long long
using namespace std;
inline int read()
{
	int x=0;bool flag=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')flag=0;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	if(flag) return x;
	return ~(x-1);
} 
inline void write(int x)
{
	if(x<0) {x=~(x-1);putchar('-');}
	if(x>9) write(x/10);
	putchar(x%10+'0');
}
/////////////////////////
const int N=2e5+50;
int n;
int a[N];
int b[N];//可翻1 
int c[N];//可翻0 
int max1,max2;
int main()
{
    freopen("count1s.in","r",stdin);
	freopen("count1s.out","w",stdout);
    n=read();
    rep(i,1,n) a[i]=read();
    drep(i,n,1) 
    {
        b[i]=b[i+1]+a[i];
        if(!a[i]) b[i]--;
        if(b[i]<0) b[i]=0;
        max1=max(max1,b[i]);
    }
    drep(i,n,1) 
    {
        c[i]=c[i+1]-a[i];
        if(!a[i]) c[i]++;
        if(c[i]<0) c[i]=0;
        max2=max(max2,c[i]);
    }
    cout<<max1+max2+1<<endl;
    return 0;
}