![]() |
VOOZH | about |
Geekina got stuck on an island. There is only one shop on this island and it is open on all days of the week except for Sunday. Consider following constraints:Examples:
Currently, itβs Monday, and she needs to survive for the next S days, initially she has no food.
Find the minimum number of days on which you need to buy food from the shop so that she can survive the next S days. If it is not possible to survive for S days then return -1.
Input : S = 10, N = 16, M = 2
Output : 2
Explanation : One possible solution is to buy a box on the first day (Monday), it's sufficient to eat from this box up to 8th day (Monday) inclusive. Now, on the 9th day (Tuesday), you buy another box and use the chocolates in it to survive the 9th and 10th day.
Input : S = 10, N = 20, M = 30
Output : -1
Explanation : You can't survive even if you buy food because the maximum number of units you can buy in one day is less the required food for one day.
Since food can only be bought for 6 days a week (shop closed on Sunday), we must ensure that the total food we can buy in a week is sufficient for 7 days of consumption.
Survival is not possible in the following cases.
If survival is possible, then compute the total food needed for S days and divide it by the maximum food we can buy per day to get the minimum buying days, i.e., days = ceil((M Γ S) / N)
2