PROBLEM LINK:
Contest Division 1
Contest Division 2
Contest Division 3
Setter: Utkarsh Gupta
Tester: Tejas Pandey, Abhinav Sharma
Editorialist: Kanhaiya Mohan
DIFFICULTY:
Cakewalk
PREREQUISITES:
None
PROBLEM:
Chef’s signature dish is a fruit chaat consisting of 2 bananas and 1 apple. He currently has X bananas and Y apples. How many chaats can he make with the fruits he currently has?
QUICK EXPLANATION:
- The answer is min(floor(X/2), Y).
EXPLANATION:
We know that a chaat requires 2 bananas and 1 apple. If we have X bananas, we can make a maximum of X/2 (rounded down) chaats from them. Similarly, from Y apples, we can make a maximum of Y chaats.
A chaat contains both the fruits, thus, the total number of chaats would be the minimum of the two values. The answer is min(floor(X/2), Y).
TIME COMPLEXITY:
The time complexity is O(1) per test case.
SOLUTION:
Editorialist's Solution
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int x, y;
cin>>x>>y;
cout<<min(x/2, y)<<endl;
}
return 0;
}