Help me in solving SUBARRAYREM problem

My issue

my question is that when we can e=remove 2 elements at a time why remove 3 ones at a time rather than 2 because if we took 2 at a time the score will be more.

My code thats working because i kept “max(0,diff) // 3” here max(0,diff) is no of ones left

t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    minCount = min(l.count(0) , l.count(1))
    diff = l.count(1) - l.count(0)
    print(minCount + max(0,diff) // 3)


### My code that not working because i kept "max(0,diff) // 2" here max(0,diff) is no of ones left 

t=int(input())
for _ in range(t):
n=int(input())
l=list(map(int,input().split()))
minCount = min(l.count(0) , l.count(1))
diff = l.count(1) - l.count(0)
print(minCount + max(0,diff) // 2)

please here me understand why we should take 3 instead of 2

Problem Link: https://www.codechef.com/problems/SUBARRAYREM

@programmer143
We r taking 3 at a time because we have to select at least two elements and selecting 2 1’s will give 0 as their xor so nothing can be contributed to our answer.
for ex:- 111111 if we take 2 one at a time the result would be 0 and if we take 3 one at a time it would give 2 as answer 1 each time .

1 Like

thank you very much for explaining