My code is getting WA in this problem -

https://www.codechef.com/BYTR20B/problems/RICY

My solution is -

https://www.codechef.com/viewsolution/40942257

My approach is - I used divide and conquer, so basically for every range I computed the prefix mins of right half and suffix min for left half and added them in 2 vectors for positions where there is a given B index, after that the way I counted the range-mins is while my left vector’s pointer is pointing to a smaller value then I increment the right pointer and vice versa, after that I add the position_of_right*value_in_left (vice versa) to my answer, and finally I add anything which is extra in any of the ranges.

Can someone explain the error?

1 Like

1

5 5

2 5 2 5 1

1 2 3 4 5

This test case gives wrong answer (randomly generated)

I have understood my mistake