-
Notifications
You must be signed in to change notification settings - Fork 0
/
A.cpp
48 lines (47 loc) · 907 Bytes
/
A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
int main()
{
fastio;
int n,i,j,ara[105],ze=0,on=0,z[105][105],o[105][105],mx=INT_MIN;
cin>>n;
for(i=0;i<n;i++)
{
cin>>ara[i];
if(ara[i]==0)
ze++;
else
on++;
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(j==i)
o[i][j]=ara[j];
else
o[i][j]=o[i][j-1]+ara[j];
}
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
if(j==i)
z[i][j]=1-ara[j];
else
z[i][j]=z[i][j-1]+1-ara[j];
}
}
for(i=0;i<n;i++)
{
for(j=i;j<n;j++)
{
int temp=on-o[i][j]+z[i][j];
mx=max(mx,temp);
}
}
cout<<mx<<"\n";
return 0;
}