# CHEFRUN - Editorial

#1

Author: Yuri Shilyaev
Editorialist: Yury Shilyaev

Cakewalk

### PREREQUISITES:

Mechanics, numbers with floating point.

### PROBLEM:

Two players are standing on a straight line at coordinates X_1 and X_2. Their goal is located at coordinate X_3. The first player runs to the goal with speed V_1, the second with V_2. The task is to find, who will came to the goal faster.

### QUICK EXPLANATION:

Refresh that the time of route S with velocity v is equal to \frac{S}{v}.

### EXPLANATION:

By the formula above, we can find time for the first player t_1 = \frac{S_1}{V_1}, where S_1 = X_3 - X_1. The time for the second player would be t_2 = \frac{S_2}{V_2}, where S_2 = X_2 - X_3. We can already solve the problem by simply comparing t_1 and t_2, but how to determine a ‘Draw’?

As you know, we can’t say that two real numbers are equal in programming language, because of precision. The best way to get rid of floating point numbers is to multiply t_1 and t_2 by V_1 \cdot V_2. The ‘Draw’ happens, when t_1 \cdot V_2 = t_2 \cdot V_1.

### AUTHOR’S AND TESTER’S SOLUTIONS:

Author’s solution can be found here.
Tester’s solution can be found here.

#2

What am I missing? It gives WA.


#include
using namespace std;
typedef long long ll;
int main() {
int t;
int x1,x2,x3,v1,v2;
cin >> t;
while(t--) {
cin >> x1 >> x2 >> x3 >> v1 >> v2;
ll chef = abs(x3-x1)*v2*1LL;
ll kefa = abs(x2-x3)*v1*1LL;
if(chef == kefa)
cout << "Draw";
else if(chef < kefa)
cout << "Chef";
else
cout << "Kefa";
cout << endl;
}
}


#3

@saketk21 You need to multiply 1LL before multiply other two…
##i.e. 1LL$abs(x3-x1)v2 ... because execution of this line will first multiply first two from left side.. that was **abs(x3-x1)*$v2** which were both integer… and hence they will become negative and then multiplying them with 1LL doesn’t help…

#4

Thanks a lot… that worked! Practice is always helpful to notice these small nuances of a programming language and not make these mistakes! @l_returns

#5

yeah true… welcome