WC '15 Contest 4 J4 - Target Practice
View as PDFWoburn Challenge 2015-16 Round 4 - Junior Division

In between missions, Bond makes sure to keep his trigger finger in shape. Today, he's hitting the firing range at MI6 headquarters.
His target consists of  
 concentric rings drawn
on a piece of graph paper, centered at the origin. The rings are
numbered 
 to 
 from smallest to largest, with the 
-th ring having
an outer radius of 
 
.
Each ring includes its outer radius, but not its inner radius – for
example, if a bullet hits exactly 
 units away from the origin,
then it's considered to land inside ring 
, but if it's slightly
further away, then it instead lands inside ring 
. If a shot
strikes no further than 
 units away from the origin, then it
naturally lands inside ring 
. The 
-th ring is worth 
 points if it's hit.
Bond has fired  
 shots at the target, with the
-th one striking at coordinates 
, and is now waiting to be notified of his total
score. Each shot will be awarded points based on which ring it landed
in, except for shots which landed strictly outside the outer radius of
ring 
, which will receive 
 points.
Q is in charge of tallying up the points, but he's decided to play a
little trick on Bond – rearranging the rings' point values! Given that
he may permute the values  in any way he'd like before
computing and adding up the 
 shots' scores, he's wondering how small
or large Bond's total score could possibly end up being. After the stunt
Bond pulled last week with taking Q's brilliant new automobile for a
little unauthorized test drive, and promptly causing it to internally
combust (and not in a good way), we can only imagine whether Q will
choose to give Bond the smallest or largest possible score… However,
in any case, can you please help him determine both of these values?
Subtasks
In test cases worth  of the points, 
 and 
.
In test cases worth another  of the points, 
 and 
.
In test cases worth another  of the points, 
 and 
.
Input Specification
The first line of input consists of two space-separated integers  and 
.
The next  lines each consist of a single integer 
, for 
.
The next  lines each consist of a single integer 
, for 
.
The next  lines each consist of two space-separated integers 
and 
, for 
.
Output Specification
Output two integers – the minimum and maximum total scores that Bond could possibly get.
Sample Input
3 5
10
100
1000
10
1
9
4 20
0 -10
1001 0
0 0
-300 -300
Sample Output
21
30
Explanation
Bond's total score is  if 
.
Bond's total score is 
 if 
.
Comments