PROBLEM LINK:
Author:Gerald Agapov
Tester:Tasnim Imran Sunny
Editorialist:Jingbo Shang
DIFFICULTY:
Cakewalk
PREREQUISITES:
Programming
PROBLEM:
GF --- (t2 - t1) --- Chef --- dist --- Home
Given t1, t2, dist, determine the time costs before GF see the gift of two plans:
- Chef waits for GF, and then goes home together.
- Chef returns home first, and goes back to GF.
EXPLANATION:
For the first plan, the answer should be (t2 - t1) + dist.
For the second one, it will be a little complicated. We need to discuss in 2 cases:
- If dist + dist <= t2 - t1, then Chef can return the bus station before GF arrived. Therefore, the answer should be t2 - t1.
- If t2 - t1 < dist + dist, then they will meet at the trip of going back. Therefore, the answer should be the middle point of the trip (imagine that the three parts as a whole): (t2 - t1 + dist * 2) / 2.
AUTHOR'S AND TESTER'S SOLUTIONS:
Author's solution can be found here.
Tester's solution can be found here.