When I first saw this problem, I felt that this problem is somewhat similar to 1068 B. Niko's Tactical Cards in which DP was used , as I haven't studied DP I was unable to solve it .
But After the contest I learn't the basic trick that first we define states , we apply operation in every state and then take min or max as the problem tells and then define the next state for further interations .
Now , I applied the same logic during solving the online mirror of 2025-2026 ICPC, NERC, Northern Eurasia Finals Problem M. Medical Parity which gave me AC 353928464 .
Similarly , I had the same intuition for going for this trick in yesterday's Good Bye 2025 C problem as there were two operations held at position 1 and 2 so I tried to define two states .
Submission -
l , r = {best X , cur left pointer , cur right pointer}
1st state — it tried to maximise the outcome of the leftmost operation by taking the best X of 1st state so far , then applying a left operation on it and a right operation on it , then reseting it to the best of the left operation of 1st state and best left operation from the 2nd state .
2nd state — it tried to maximise the outcome of the rightmost operation by taking the best X of 2st state so far , then applying a left operation on it and a right operation on it , then reseting it to the best of the right operation of 1st state and best right operation from the 2nd state .
I did a dry run and it It perfectly worked on pretests 1 but somehow fails on pretests 2 . Is there a flaw in my logic or did someone implemented a similar approach and got AC . Can anyone Help ..
Plus , It's my first blog :D




