Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|

Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |

Language: Commuter train
Description You might have noticed that bus drivers sometimes pass by passengers waiting for the bus and stop at a place where the distance from the people to the bus doors is maximal. We don’t know exact reasonsof such behaviour, probably, this is done not because of some special wickedness of the driver but in order to allow passengers in the vehicle to get off quicker. However, we know that in one far-away countrythe government decided to implement automatic driving system on their commuter railroads. Amongother features, this system is intended to automatically stop commuter trains at stations. A computer in the train is connected to a special radar, which determines passenger positions at the station platform. The computer decides where to stop the train in order to maximize the sum of the distances from each passenger to the closest door. All the hardware is ready, but the software project is late (transport problems). Your task is to implement this function for this software project.
More precisely: The platform has length 0 < L <= 5000. There are 0 < M <= 300 passengers at the station platform. Each passenger p has position Pp (0 <= P1 <= ... <= PM <= L) — the distance from the platform beginning to the passenger. There are 0 < N <= 300 doors in the train. Each door d has position Dd (0 = D1 < D2 < ... < DN <= L) -- the distance from it to the door 1. The door width and the passenger sizes are not taken into account. For simplicity, you can assume that the distance between a passenger i and a train door j is dist(i, j, S) = |Dj + S - Pi|, where S is train position -- the distance between the first door and the beginning of the platform. Remember that the train must stop so that no door is outside of the platform. Input The input contains integer numbers, separated by spaces and/or line feeds. At the beginning of the file
there is the station description L, M, and P1 ... PM, followed by the train description N and D2 ... DN. Output You should output two numbers -- the train position S, at which the maximal possible sum of the minimal distances between the passengers and the doors can be achieved and the sum by itself. If there are many such train positions -- output any one. Sample Input 4 5 0 1 2 3 4 4 1 2 3 Sample Output 0.5 2.5 Source Northeastern Europe 2002, Northern Subregion |

[Submit] [Go Back] [Status] [Discuss]

All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di

Any problem, Please Contact Administrator