P1293 Class Reunion
Description
Twenty-five years after graduation, our protagonist starts preparing a class reunion. After countless phone calls, he finally obtains the addresses of all classmates. Some still live in the same city, but most are scattered in other cities. However, he notices a coincidence: all addresses happen to lie along a single railway line. He plans to set out to invite them but cannot decide where to hold the banquet. In the end, he decides to choose a location that minimizes the sum of everyone’s travel costs.
Unfortunately, our protagonist is neither good at math nor computers. He asks you to write a program that, given his classmates’ addresses, selects the best reunion location. If the total cost is tied, choose the city closer to Moscow.
Input Format
Each line of the input data describes one city. For each city, first comes the number of classmates living in that city, followed by the distance from this city to Moscow (the starting station) in $\rm km$, and finally the city name. The last line always describes Moscow, which lies at one end of the railway line and has distance $0$.
Output Format
Output the city name of the meeting location and the travel cost (one-way), separated by a single space. Each $\rm km$ costs one ruble.
Explanation/Hint
Constraints
For all testdata, it is guaranteed that the number of cities $ \le 150$, the distance $ \le 10000$, and the number of classmates $ \le 50$.
Translated by ChatGPT 5