记录编号 572303 评测结果 AAAAAAAAAA
题目名称 Count 1s 最终得分 100
用户昵称 GravatarHeSn 是否通过 通过
代码语言 C++ 运行时间 0.127 s
提交时间 2022-06-30 15:44:00 内存使用 3.25 MiB
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n, a[200100], ans = 0;
int fmx() {
	int maxn = 0, sum = 0;
	for(int i = 1; i <= n; i ++) {
		maxn = max(a[i], maxn + a[i]);
		sum = max(sum, maxn);
	}
	return sum;
}
int fmn() {
	int minn = 0, sum = 0;
	for(int i = 1; i <= n; i ++) {
		minn = min(a[i], minn + a[i]);
		sum = min(sum, minn);
	}
	return sum;
}
int main() {
	freopen("count1s.in", "r", stdin);
	freopen("count1s.out", "w", stdout);
	cin >> n;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
		if(a[i] == 0) {
			a[i] = -1;
		}
	}
	cout << fmx() - fmn() + 1 << endl;
	return 0;
}