WATERCOOLER2-Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Lavish Gupta
Tester: Istvan Nagy, Aryan
Editorialist: Vijay

DIFFICULTY:

Cakewalk

PREREQUISITES:

None

PROBLEM:

The summer is at its peak in Chefland. Chef is planning to purchase a water cooler to keep his room cool. He has two options available:

  • Rent a cooler at the cost of X coins per month.
  • Purchase a cooler for Y coins.

Chef wonders what is the maximum number of months for which he can rent the cooler such that the cost of renting is strictly less than the cost of purchasing it.

EXPLANATION:

What will be the cost of renting a water cooler for K months ?

The cost of renting a water cooler for one month equals X. Then the cost of renting a water cooler for K months will be equal to X+X+...... K times =K \cdot X.

Up to when will Chef prefer renting a water cooler instead of buying it?

Chef will rent when the cost of renting is strictly less than the cost of buying a water cooler.
The cost of renting the cooler for K months equals K \cdot X. And, also the cost of buying a new water cooler equals Y. So, Chef will continue to rent up until K months such that K\cdot X<Y=>K= { \frac{Y-1}{X}} which is rounded down.

TIME COMPLEXITY:

O(1) for each test case.

SOLUTION:

Editorialist's Solution


#include <bits/stdc++.h>
using namespace std;
#define nline '\n'


int main()
{   
   
    int t;
    cin >> t;

    while (t--)
    {
         int x, y;
         cin>>x>>y;
         int m=(y-1)/x;

         cout<<m<<nline;
     
    }
}