MTHUR - grace marks
In earlier days, grading in BITS used to be absolute, instead of relative grading scheme. Once Professor Mathur decided to conduct a surprise quiz, and many students were caught unaware of it. Their scores of the students came out to be much worse than the previous years scores.
Professor Mathur really believed that true test of talent comes in difficult situations and continued such horrifying sequences of tests. But finally poor placements of his students turned the heat up for the professor and he decided to revise everyone's marks.
Now being a qualified mathematician, professor Mathur applied a simple strategy to this. He decided to award some constant grace marks to each and every student. He took every students last year marks and then added up the absolute difference with the revised current year marks. And he decided to choose the grace marks with the least sum of absolute difference. I.e. sum(abs (a[i] - (b[i]+grace))) should be minimum. Also, professor Mathur had a knack of choosing the grace value from his set of favourite numbers.
Now that our students are happily placed in 'Microsoft', 'Adobe' for the good , credit finally goes to Professor Mathur.
Now, decide for each input, what grace marks were given by Mathur. (If there are many such grace marks, choose the lowest one).
Input
First line, t for number of test cases. Next 5*t line for each test case.
First line of every testcase: integer n.
Second line: n integers showing previous years marks of every student.
Third line: n integers showing present years marks of every student.
Fourth line: integer m.
Fifth line: m integers showing the possible values for grace marks.
Output
Output the expected grace marks.
Example
Input: 1
5
9 10 7 3 10
4 1 4 1 3
6
0 1 2 3 4 5
Output: 5
Constraints
number of testcases, t < 20
maximum number of students: n < 10000
1 <= m, marks[i] <= 50000
hide comments
Romal Thoppilan:
2012-10-02 00:33:15
m>=1 ,
|
|
well i am lagging:
2012-10-02 00:33:15
can the value of m be zero as it is given in constraint and if yes then what would be the grace vaule? |
|
!@#$:
2012-10-02 00:33:15
Is there a possibility that for a particular student his current year marks are greater than previous year marks ? |
|
Romal Thoppilan:
2012-10-02 00:33:15
Yes , there exists duplication in possible grace values .
|
|
well i am lagging:
2012-10-02 00:33:15
Can we have repeated numbers in possible grace values?
|
|
Romal Thoppilan:
2012-10-02 00:33:15
Assuming the grace marks being 5 , sum = abs(9-(4+5))+abs(10-(1+5))+abs(7-(4+5))+abs(3-(1+5))+abs(10-(3+5)) = 11 , this value is least value of sum for any grace value taken Last edit: 2012-08-20 17:00:08 |
|
Pranjali Pratik:
2012-10-02 00:33:15
could you explain the testcase... |
|
Romal Thoppilan:
2012-10-02 00:33:15
Problem statement is updated . Instead of square difference , absolute difference is evaluated
|
|
Vaishali Behl:
2012-10-02 00:33:15
Please explain the problem statement again. It is very ambiguous. |
Added by: | Romal Thoppilan |
Date: | 2012-08-20 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM32-GCC ASM64 MAWK BC C-CLANG NCSHARP CPP14 CPP14-CLANG COBOL COFFEE D-CLANG D-DMD DART ELIXIR FANTOM FORTH GOSU GRV JS-MONKEY JULIA KTLN NIM NODEJS OBJC OBJC-CLANG OCT PERL6 PICO PROLOG PYPY PYPY3 PY_NBC R RACKET RUST CHICKEN SQLITE SWIFT UNLAMBDA VB.NET |
Resource: | own problem |