CLBATH - Editorial

PROBLEM LINK

Practice
Contest

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

t_3 = \frac{v_x t_1 + v_y t_2}{v_x + v_y}

Manipulating the equation, we get

\frac{v_x}{v_y} = \frac{t_2 - t_3}{t_3 - t_1}

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

\frac{v_x}{v_x + v_y} \cdot v_3 \le v_1 \\ \frac{v_y}{v_x + v_y} \cdot v_3 \le v_2

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.

2 Likes

given constraints is t2>t1

Yes, as @goti158 said, t2 must be greater than t1

how the conditions of getting volume v3 is working? basically how to get that conditions??