TopCoder problem "GradingSystem" used in SRM 264 (Division II Level One)



Problem Statement

    A certain professor has come up with two grading schemes. Each of his students has received a definite score in the course between 0 and 100 points, inclusive. The scores for all the students are given in the int[] scores, which will be sorted from least to greatest. Students will end up with an integer grade between 0 and 8 points. He has mentally assigned desired grades to each student. The i-th element of scores corresponds to the i-th element of grades. Grades corresponding to equal scores will be sorted greatest to least.



In the first scheme, if he desires a certain student to have a grade of X, then every student scoring as high or higher than that student must receive a grade of at least X. Aside from this constraint, students will be given the lowest possible grade. For example, suppose 3 students had scores of {60,80,80} and the professor desired them to have grades of {3,8,6}. They would then recieve grades of {3,8,8}, since the third student scored at least as high as the second.



In the second scheme, if he desires a certain student to have a grade of X, then every student scoring as low or lower than that student must receive a grade of at most X. Aside from this constraint, students will be given the highest possible grade. In the above example, the students would recieve grades of {3,6,6} now, since the second student scored at least as low as the third.



You should apply both schemes, and for each student, determine the absolute difference between the final grades obtained from the two schemes. Return the sum of those differences.
 

Definition

    
Class:GradingSystem
Method:fairness
Parameters:int[], int[]
Returns:int
Method signature:int fairness(int[] scores, int[] grades)
(be sure your method is public)
    
 

Constraints

-scores will contain between 1 and 50 elements, inclusive.
-scores and grades will contain the same number of elements.
-Each element of scores will be between 0 and 100, inclusive.
-Each element of grades will be between 0 and 8, inclusive.
-scores will be sorted least to greatest.
-Elements of grades corresponding to equal elements of scores will be sorted greatest to least.
 

Examples

0)
    
{60,80,80}
{3,8,6}
Returns: 4
The example in the description.
1)
    
{0,25,50,75,100}
{0,1,3,6,8}
Returns: 0
Here the professor's expectations are exactly in line with the students' performances.
2)
    
{0,25,50,75,100}
{8,6,3,1,0}
Returns: 40
Here the performances and the expectations are severely different.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4782

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7998&pm=4782

Writer:

Enogipe

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Sorting