Canadian Computing Competition: 2021 Stage 1, Senior #3
It's lunchtime at your school! Your friends are all standing on a long field, as they usually do. The field can be represented as a number line, with the friend initially at position metres along it. The friend is able to walk in either direction along the field at a rate of one metre per seconds, and their hearing is good enough to be able to hear music up to and including metres away from their position. Multiple students may occupy the same positions on the field, both initially and after walking.
You're going to hold a little concert at some position metres along the field (where is any integer of your choice), and text all of your friends about it. Once you do, each of them will walk along the field for the minimum amount of time such that they end up being able to hear your concert (in other words, such that each friend ends up within units of ).
You'd like to choose such that you minimize the sum of all of your friends' walking times. What is this minimum sum (in seconds)? Please note that the result might not fit within a -bit integer.
The first line of input contains .
The next lines contain three space-separated integers, , , and ().
The following table shows how the available marks are distributed.
| Subtask | ||||
|---|---|---|---|---|
| 4 marks | ||||
| 9 marks | ||||
| 2 marks |
Output one integer which is the minimum possible sum of walking times (in seconds) for all of your friends to be able to hear your concert.
If you choose , your single friend won't need to walk at all to hear it.
One possible optimal choice of is , which would require your first friend to walk to position (taking seconds) and your second friend to walk to position (taking seconds), for a total of seconds.
No comments yet. Be the first to comment!