Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n, mx = 0, i, j, k, cnt1, cnt2, m, mxx = 0;
- cin>>n;
- int dp[n+1];
- int arr[n+1];
- arr[0] = 0;
- dp[0] = 0;
- int mov = 0;
- for(i = 1; i <= n; i++)
- {
- cin>>arr[i];
- if(arr[i] == 1)
- {
- dp[i] = dp[i-1]+1;
- }
- else
- {
- dp[i] = dp[i-1];
- }
- }
- for(i = 1; i <= n; i++)
- {
- for(j = i; j <= n; j++)
- {
- cnt1 = dp[i - 1] + dp[j] - dp[i - 1] + dp[n] - dp[j];
- cnt2 = dp[i - 1] + j - (i - 1) - (dp[j] - dp[i - 1]) + dp[n] - dp[j];
- mx = max(mx, max(cnt1, cnt2));
- if(mx == cnt2)
- {
- mov++;
- }
- }
- mxx = max(mxx, mx);
- }
- if(mov == 0)
- {
- mxx--;
- }
- cout<<mxx;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement