Timer is Running

Check if it is possible to survive on Island
Submissions: 3323   Accuracy:


  Difficulty: Easy   Marks: 2

Ishika 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:

  • N – The maximum unit of food you can buy each day.
  • S – Number of days you are required to survive.
  • M – Unit of food required each day to survive.

Currently, it’s Monday, and she needs to survive for the next S days.
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, or determine that it isn’t possible to survive.

The first line of the input an integer T, the number of test cases. For each test case, there are three integers s, n, m denoting the number of days she is required to survive, the maximum unit of food that she can buy each day and unit of food that is required each day to survive respectively.

For each test case, the output is an integer displaying the minimum number of days she needs to buy food and if she can't survive return -1.



10 16 2
10 20 30

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.
2. She can’t survive even if she buy food because the maximum number of units she can buy in one day is less the required food for one day.

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Vanshika
Author: vanshi_14

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.