F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Minimize The Difference

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 864    Accepted Submission(s): 504


Problem Description
Recently, Kiki are asked to arrange a competition. Before the competition, everyone have an expectation of the ranking. To make all the players happy , Kiki wants to minimize the sum of all the players¡¯ difference. We define the difference of a player as |ai-bi|, ai stands for one¡¯s expected ranking ,and bi stands for one¡¯s final ranking.
 

Input
There are several test cases.
Each case begins with an integer n ,(n<= 100)stands for the number of players in this competition.
Then follows n lines ,each line contains a string s and an integer m,(the string will contains no more than 20 characters and no space in it, 1<=m<=n) stands for the name of the player and his expected ranking.
 

Output
The output contains one line for each data set : the minimum sum of differences Kiki can get.
 

Sample Input
7 a 1 b 2 c 2 d 1 e 5 g 7 f 7
 

Sample Output
5
 

Hint

Hint
One possible solution
1. a2. d3. b4. c5. e6. g7. f
 

Author
dandelion
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-04 08:34:14, Gzip enabled