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.
Input Specification
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 | ||||
---|---|---|---|---|
marks | ||||
marks | ||||
marks |
Output Specification
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.
Sample Input 1
1
0 1000 0
Output for Sample Input 1
0
Explanation of Output for Sample Input 1
If you choose , your single friend won't need to walk at all to hear it.
Sample Input 2
2
10 4 3
20 4 2
Output for Sample Input 2
20
Explanation of Output for Sample Input 2
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.
Sample Input 3
3
6 8 3
1 4 1
14 5 2
Output for Sample Input 3
43
Comments
OMG my friend Sam thought of a solution in 5s
This comment is hidden due to too much negative feedback. Show it anyway.
Unfortunately, your code is because of
a = sorted(a, key=lambda x: x[0])
I would recommend you to post it in the editorial instead of here
This comment is hidden due to too much negative feedback. Show it anyway.
because it is printing the wrong answer or taking too long to print the wrong answer.