牛客578103972号:第二题:
#include<iostream>
(5488)#include<vector>
#include<algorithm>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> v(N);
int sum = 0;
for (int i = 0; i < N; i++) {
cin >> v[i];
sum += v[i];
}
int flag = -1;
if (v[0] == 0) flag = 1;
int cur = flag;
int max1 = cur;
for (int i = 1; i < N; i++) {
flag = -1;
if (v[i] == 0) flag = 1;
cur = max(flag, cur + flag);
max1 = max(max1, cur);
}
cout << sum + max1 << endl;
}
投递拼多多集团-PDD等公司10个岗位 >
0 点赞 评论 收藏
分享
关注他的用户也关注了: