codeforces 192a
July 22, 2013
CodeForces
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[102];
int main ( int argc, char *argv[] )
{
#ifndef ONLINE_JUDGE
freopen("191a.in", "r", stdin);
#endif
int n, n1=0, cnt=0, Max=0; scanf("%d", &n);
for (int i=0; i<n; ++i){
scanf("%d",a+i); if(a[i]) n1++;
}
if (n1 == n) Max = n1-1;
else
{
Max = n1;
for (int i=0; i<n; ++i) {
for (int j=0; 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……