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
I found a way to AC without binary search and with time time complexity of o(n) just consider a function like this: f(x) = this means on point can be considered as two points with half of the weight and D = 0. Then finally minus WD when you calculate the time but if you directly calculate WD's sum will cause numerical overflow so it will be better to minus 1/2WD each time
https://dmoj.ca/src/6088148
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.