PROBLEM LINK
Author and Editorialist: Soumik Sarkar
Tester: Avijit Agarwal
DIFFICULTY
SIMPLE
PREREQUISITES
Basic maths
PROBLEM
There are two buckets of water. The water in the first bucket has volume v_1 and temperature t_1. The water in the second has volume v_2 and temperature t_2. It is given t_1 < t_2 and the problem to find if some water from the 2 buckets can be combined to get at least v_3 volume at temperature t_3 .
EXPLANATION
First of all, it is impossible to get water at temperature less than t_1 or more than t_2. After this check there can be multiple more-or-less equivalent methods to solve this problem. Author’s solution is as follows.
Mixing v_x volume of water at temperature t_1 with v_y volume of water at temperature t_2 yields water at temperature t_3, where
Manipulating the equation, we get
This is the fixed ratio in which the water from the two buckets must be mixed to get temperature t_3.
To get v_3 volume, the conditions
must hold.
Time complexity is \mathcal{O}(1) per case.
AUTHOR’S AND TESTER’S SOLUTIONS
Author’s solution can be found here
Tester’s solution can be found here.