Suppose there is an island. There is only one store in that location, this store remains open always except Sunday. We have following values as input −
If it is Monday, and we need to survive for the next S number of days. We have to check whether we can survive or not, if we can find the minimum number of days on which we need to buy food, so that we can survive the next S number of days.
So, if the input is like S = 12, N = 24, M = 3, then the output will be True and minimum number of days on which we need to buy food is 2, as we can survive 8 days (from current Monday to next Monday) using 24 units of food, then buy again 12 units for next 4 days.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(S, N, M): if ((N * 6) < (M * 7) and S > 6) or M > N: return False else: count = (M * S) // N if ((M * S) % N) != 0: count += 1 return (True, count) S = 12 N = 24 M = 3 print(solve(S, N, M))
12, 24, 3