COW205 - Editorial

PROBLEM LINK:

Practice
Contest

Author: Sunita Sen
Tester: Arnab Chanda , Sandeep Singh
Editorialist: Sunita Sen
Video Editorial: Link

DIFFICULTY:

EASY

PREREQUISITES:

None

PROBLEM:

Given the height of each scoop of ice-cream a, find the minimum and maximum number of scoops we need to add such that the height of ice-cream is range [l,r].

EXPLANATION:

Minimum height of the ice-cream must be greater than or equal to l. So, what is the minimum number of scoops we should add such the the total height is greater or equal to l? First, lets find out what will the minimum height. Minimum Height will be the smallest multiple of a, say p such that p >= l. Hence, minimum number of scoops should be ceil(l/a).
Similarly, the maximum number of scoops to be added is floor(r/a).
Lastly, is there a case, in which no answer is possible? Yes. When the minimum height exceeds r or maximum height is less than l.

SOLUTIONS:

Cpp Solution
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(){
	ll t;
	cin>>t;
	while(t--){
		ll l,r,a;
		cin>>l>>r>>a;
		ll k = ceil(1.0 * l/a);
		ll k1 = r/a;
		if(k*a>r || k1*a<l){
			cout<<-1<<" "<<-1<<endl;
		}
		else cout<<k<<" "<<k1<<endl;
	}
	return 0;
} 


2 Likes