#Lutece0929. Post office
Post office
Migrated from Lutece 929 Post office
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
There are villages along a straight road, numbered from to for simplicity. We know exactly the position of every one (noted pos,pos is positive integer and pos). The local authority wants to build a post office for the people living in the range to j(inclusive). He wants to make the sum of |posposition_of_postoffice| is minimum.
Input
For each test case, the first line is . Then integer, representing the position of every village and in ascending order. Then a integer , representing the queries. Following lines, every line consists of two integers and . the input file is end with EOF
. Total number of test case is no more than .
Be careful, the position of two villages may be the same.
Output
For every query of each test case, you tell the minimum sum.
Samples
3
1 2 3
2
1 3
2 3
2
1
Note
Huge input,scanf
is recommend.
Resources
2011 Heilongjiang collegiate programming contest