All Submissions


We have n numbers a1, a2, a3.... aN. Each of these numbers can be either 0 or 1. you have to choose two index i, j (1<=i<=j<=N) and
toggle all the numbers in between it(including numbers at index i and j), such that number of 1's in the given sequence(i.e from a1....aN) is maximized.

P.S: The above operation is applied once only.

INPUT:
your first line contains number of test cases.
Each test case contains,
the first line of test case contains N
the second line of each test case contains n numbers
each test case is separated by a blank line.

Output:
output of each test case is the maximum number of 1's after performing the above operation.

Sample Input:
3
4
1 1 0 0

3
0 1 0

5
1 1 0 1 1

Sample Output:
4
2
5



1<=N<=1000000
1<=T<=110

Problem Setter : Sumit Kumar
Problem Tester: Akshit Poddar

Languages: AWK,Bash,Brain,C,C++,Java,C#,JavaScript,Pascal,Perl,PHP,Python,Python3,Ruby,Text

Time Limit: 5 Second(s)
Score: 0 Point(s)
Input File Limit: 50000 Bytes

Submit

Login to post clarification.

No Clarifications.

Contest

Mode Judge

Passive

Online

Overall Rankings

RankNameScore
1xyz0
2Ams0
3TIP0
4team420
5xyzz0
6asdasdasd0
7abcd0
8khankhan0
9Gabriel0
10gigel0