Stucked in FloorI4

ad-hoc

#1

Problem Link:
https://www.codechef.com/SEPT14/problems/FLOORI4/

I am not getting the concept to solve this question. i also tried to read the editorials and solutions but all in vain.Can anyone please explain me in detail how to solve this and what is the tricky thing that needs to be observed??