Commuter train
Time limit2sMemory limit64 MB
Pick the train stopping position inside the platform that maximizes the total nearest-door distance over all passengers, and print twice that maximum.
- Level
Medium6 of 10
- Topics
- Brute force, Sorting
- Solved
- No attempts yet
Problem
Bus drivers sometimes roll past the people waiting at a stop and park where the walk to the nearest door is as long as it can be. Nobody knows why. Probably not out of spite: while the boarding crowd walks over, the passengers already on board get more room to step off.
In one far away country the government decided to put an automatic driving system on its commuter railroad. One job of that system is stopping trains at stations. A radar reports where every passenger stands on the platform, and the on-board computer picks the stopping position that maximizes the sum over all passengers of the distance from that passenger to the door closest to them. The hardware is ready and the software is late. Write that function.
The platform has length . There are passengers on it, and passenger stands at distance from the start of the platform, where . The train has doors, and door sits at distance from door 1, where . Door widths and passenger sizes are ignored.
The stopping position of the train is the distance from the start of the platform to door 1. With the train at , the distance between passenger and door is . No door may hang off the platform, so and . does not have to be an integer. It can be any real number in that range.
Input
The input holds integers separated by spaces and line breaks. The platform description comes first: , then , then . The train description follows: , then . is always 0 and is left out of the input, so the train description is integers in total.
, , .
Output
Write for the total the computer wants to maximize. Take the largest value of over every legal stopping position , multiply it by 2, and print the result.
That largest value is always a multiple of , so twice it is an integer. Print that one integer.