Submit | All submissions | Best solutions | Back to list |
BAISED - Biased Standings |
Usually, results of competitions are based on the scores of participants. However, we are planning a change for the next year of IPSC. During the registration each team will be able to enter a single positive integer : their preferred place in the ranklist. We would take all these preferences into account, and at the end of the competition we will simply announce a ranklist that would please all of you.
But wait... How would that ranklist look like if it won't be possible to satisfy all the requests?
Suppose that we already have a ranklist. For each team, compute the distance between their preferred place and their place in the ranklist. The sum of these distances will be called the badness of this ranklist.
Problem specification
Given team names and their preferred placements find one ranklist with the minimal possible badness.
Input specification
The first line of the input file contains an integer T specifying the number of test cases. Each test case is preceded by a blank line.
Each test case looks as follows: The first line contains N : the number of teams participating in the competition. Each of the next N lines contains a team name (a string of letters and numbers) and its preferred place (an integer between 1 and N, inclusive). No two team names will be equal.
Output specification
For each of the test cases output a single line with a single integer : the badness of the best ranklist for the given teams.
Example
Input: 2 7 noobz 1 llamas 2 Winn3rz 2 5thwheel 1 NotoricCoders 5 StrangeCase 7 WhoKnows 7 3 ThreeHeadedMonkey 1 MoscowSUx13 1 NeedForSuccess 1 Output: 5 3Explanation:
In the first test case, one possible ranklist with the minimal badness is:
1. noobz 2. llamas 3. Winn3rz 4. 5thwheel 5. NotoricCoders 6. WhoKnows 7. StrangeCase
In the second test case all ranklists are equally good.
Note: the input file will not exceed 5MB.Added by: | Fudan University Problem Setters |
Date: | 2007-12-01 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: C99 ERL JS-RHINO |
Resource: | IPSC 2006 |
hide comments
|
||||||||||
2012-12-14 10:53:50 Pranshul Agarwal
O(n) worked for me.. :D Team name doesn't matter.. |
||||||||||
2012-08-19 19:51:36 AC Srinivas
team name doesn't matter right? |
||||||||||
2012-08-19 19:46:13 AC Srinivas
any specific test cases? getting WAs. |
||||||||||
2012-03-03 17:19:44 saket diwakar
yes...O(N) works... |
||||||||||
2011-06-30 14:12:50 .::Manish Kumar::.
Guys, plz don't write things like O(nlogn), it always tells me to do something with the input, and then it becomes a spoiler. |
||||||||||
2010-10-05 07:43:04 :D
It can be solved in O(N). Plus N can be bigger that sqrt(2^32) ;) |
||||||||||
2010-06-14 09:40:59 Kick
Any better algorithm other than O(NlogN)?? |
||||||||||
2010-04-15 11:47:31 :(){ :|: & };:
It's a problem where you have to assume every constraints :P |
||||||||||
2009-10-08 03:16:02 [Trichromatic] XilinX
It's an error when applying the problem code. |
||||||||||
2009-04-14 21:12:39 Paul Draper
why is the name baised? |