link: http://codeforces.com/contest/330/problem/A
brute force.
/*
ID: zypz4571
LANG: C++
TASK: 191a.cpp
*/ #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <algorithm>
#include <queue>
#include <set>
#include <queue>
#include <list>
#include <map>
#define INF 0x3f3f3f3f
#define mid int m=(l+r)/2
using namespace std;
int a[];
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("191a.in", "r", stdin);
#endif
int n, n1=, cnt=, Max=; scanf("%d", &n);
for (int i=; i<n; ++i){
scanf("%d",a+i); if(a[i]) n1++;
}
if (n1 == n) Max = n1-;
else
{
Max = n1;
for (int i=; i<n; ++i) {
for (int j=; j<n; ++j) {
cnt = n1;
for (int k=i; k<=j; ++k) {
if (!a[k]) cnt++; else cnt--;
}
if (cnt > Max) Max = cnt;
}
}
}
printf("%d\n", Max); return EXIT_SUCCESS;
} /* ---------- end of function main ---------- */
It is so easy. However, I got a WA at first. sad......