Last Updated: 13 Feb, 2021

Check if Possible to survive

Easy
Asked in company
Ola

Problem statement

You are a poor citizen of an island that has only one shop for groceries, which is open six days a week and is closed on Sundays. The first day of the week is Monday. You can buy ‘n’ units of food from a day’s work. Now each day, you need ‘x’ units of food to survive. You are making a boat to escape the island, which will require ‘d’ days to be made. You need to survive at least ‘d’ days on the island. You are given three integers n, x, and d. Your task is to determine if you can escape the island

Input Format:
The first line of input contains an integer ‘T’ denoting the number of test cases to run. Then the test cases follow.

The first and the only line of each test case contains three space-separated integers n, x, and d.
Output Format
For each test case, print YES if it is possible to survive on the island; else, print NO.

Output for each test case will be printed in a separate line.
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 10^4
1<= n, m, d<=10^8

Where ‘T’ is the total number of test cases and n denotes the units of food the citizen can buy from one day salary, x denotes the units needed to survive each day and d denotes the minimum number of days the citizen needs to survive on the island to escape it.   

Time limit: 1 sec

Approaches

01 Approach

The key idea in solving this problem is to buy each day on which purchase is possible, i.e., six days a week, and try to survive for seven days. If we can survive for one week by induction, we can say that we can survive for any number of days. To survive for one week, we need first to ensure that we can survive for a day.

      The algorithm will be -

  • If the number of days needed to survive is greater than six, we need to ensure that the amount of food we buy in 6 days is enough to survive the 7th day, which is a Sunday, i.e., if 6 * n >= 7 * x, we can survive any number of days.
  • One corner case will be that if we need to survive less than seven days, we need to ensure that we can survive one day i.e., n >= x.
  • In all other cases, the citizen will die.