guys I got the logic part but I m unable to implement it .it would be great and really appreciated if you kindly share your approach and your solution with little explaination so that I could get it .it is a problem from codechef may long challenge 2020 here is the link to the problem https://www.codechef.com/MAY20B/problems/CHANDF just copy it and paste in the URL section. thanks for your time.if anyone have any doubt you can ask about it too related to the above mentioned problem.
Hey, but the editorial section on the CodeChef https://discuss.codechef.com/t/chandf-editorial/63302 is very exhaustive. Although, it contains two solutions which follow the editorial. Do you still have questions?
Also, video editorial is here: https://www.youtube.com/watch?v=rzaP4qd-b_M&t=698s
See this.