Hackerearth question

can someone please help with this questions plz

what is the logic and how to implement?
actually its my first time doing competitive coding and i am really having difficulty solving questions there

just start from 0 to number of flower pots n get two variable from starting and ending point in the while loop and make all combination and store the minimum in the ans and cout that ans ,
but this will pass only your half case as complexity is high according to question n^2,
for all test cases u have to do it in nlogn complexity so try to think about to implement binary search