Class Party (Reunion)

Source: Internet
Author: User
Tags time limit

Connection http://59.61.75.5:8888/JudgeOnline/showproblem?problem_id=1589

Class gathering 2010-10-31 Universal Simulation (Reunion)

Time limit:1000ms Memory limit:65536k
Total submit:77 accepted:22

Description

25 years after graduation, our hero begins to prepare for the reunion. After making countless calls, he finally got the address of all the students.
Some of them are still in the city, but most people are scattered in other cities.
However, he found a coincidence that all the addresses were scattered across a railroad line. He was ready to leave for the invitation but could not decide where to hold the party.
In the end he decided to choose a location that would make everyone's trip cost and minimum.
Unfortunately, our hero is neither good at maths nor computer. He asked you to help write a program, according to his classmate's address, choose the best place for the party.

Input

Each line of the input file describes a city's information, up to 100,000 cities.

The first is the number of students in the city (<=1000);
followed by the city to Moscow (starting point) (<=maxlongint);
Finally, the name of the city (less than 200 characters in length).

The last line describes the always Moscow, which is at one end of the rail, with a distance of 0.

Output

Party location city name and travel fee (one way), separated by a space. Cost one rub per km.

Sample Input

7 9289 Vladivostok	
5 8523 Chabarovsk
3 5184 Irkutsk
8 2213 Yalutorovsk
0 Moscow

Sample Output

Yalutorovsk 112125

Program P1589; var n,sum:longint; NAME:ARRAY[0..100001] of string; NUM,D:ARRAY[0..100001] of Longint; Procedure Init; var Ch:char; Begin N:=1; Read (Num[n],d[n]); Read (CH); READLN (Name[n]); Sum:=num[n]; While POS (' Moscow ', name[n]) =0 does begin Inc (n); Read (Num[n],d[n]); Read (CH); READLN (Name[n]); Sum:=sum+num[n]; End End Procedure sort (s,e:longint); var i,j,tnum,td,r:longint; tname:string; Begin I:=s; J:=e; R:=random (e-s) +s; TNUM:=NUM[R]; TD:=D[R]; TNAME:=NAME[R]; Num[r]:=num[s]; D[r]:=d[s]; Name[r]:=name[s]; While I<j does begin while (I&LT;J) and (D[J]&LT;TD) does Dec (j); If I<j then begin D[I]:=D[J]; NUM[I]:=NUM[J]; NAME[I]:=NAME[J]; Inc (I); End while (I&LT;J) and (D[I]&GT;TD) do Inc (I); If I<j then begin d[j]:=d[i]; Num[j]:=num[i]; Name[j]:=name[i]; Dec (j); End End Num[i]:=tnum; D[I]:=TD; Name[i]:=tname; If S<i-1 then sort (s,i-1); If J+1<e then sort (j+1,e); End procedure work; var mid,total,i,j:longint; Tint64:int64; Begin//for I:=1 to n do Writeln (Num[i], "', d[i], '', Name[i]); mid:= (sum+1) Div 2; total:=0; For I:=1 to n does begin if Total+num[i]>mid then begin break end else total:=total+num[i]; End Write (Name[i], "); tint64:=0; For J:=1 to N do tint64:=tint64+abs ((d[j]-d[i)) *num[j]; Writeln (Tint64); End Begin init; Sort (1,n); Work End.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.