height of the smallest plant?

This question was asked in Apostek coding challenge (Elitmus).The challenge has ended few days ago.I was not able to solve it then and now I wish to know how to solve it. Question is:-
Lucy wants to give her teacher plants for her birthday. Lucy wants to grow the plants by herself by watering them each day. There are N plants. When we water a plant, it grows by 1 unit height. Watering can be done only once a day. We have M number of days left for teacher’s birthday.
Some extra conditions are: W denotes that lucy has to water W continuous plants in each watering.
K denotes that each plant can be watered a maximum of K times(and not more than that).
We have to find the height of the smallest plant after M days.
Thanks!!