Need optimization in CHCBOX

I am getting time limit error in problem CHCBOX.
problem link:-https://www.codechef.com/COOK116B/problems/CHCBOX/
my approach:-https://www.codechef.com/viewsolution/30666215
please help…

Your logic is also wrong
for this test case
your answer is
1
3
2 3 2 1 1 3

but it should be 4
2 1 1 3 2 3

use prefix sum approach

1 Like