WC '15 Contest 4 J4 - Target Practice

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 1.8s
Memory limit: 64M

Author:
Problem types
Woburn 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 N (1 \le N \le 10^5) concentric rings drawn on a piece of graph paper, centered at the origin. The rings are numbered 1 to N from smallest to largest, with the i-th ring having an outer radius of R_i (1 \le R_1 < R_2 < \dots < R_N < 10^9). Each ring includes its outer radius, but not its inner radius – for example, if a bullet hits exactly R_i units away from the origin, then it's considered to land inside ring i, but if it's slightly further away, then it instead lands inside ring i+1. If a shot strikes no further than R_1 units away from the origin, then it naturally lands inside ring 1. The i-th ring is worth P_i (1 \le P_i \le 1\,000) points if it's hit.

Bond has fired M (1 \le M \le 10^6) shots at the target, with the i-th one striking at coordinates (X_i, Y_i) (-10^9 \le X_i, Y_i \le 10^9), 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 N, which will receive 0 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 P_{1 \dots N} in any way he'd like before computing and adding up the M 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 6/40 of the points, N \le 10 and M \le 20.
In test cases worth another 10/40 of the points, N \le 800 and M \le 400.
In test cases worth another 12/40 of the points, N \le 10^5 and M \le 400.

Input Specification

The first line of input consists of two space-separated integers N and M.
The next N lines each consist of a single integer R_i, for i = 1 \dots N.
The next N lines each consist of a single integer P_i, for i = 1 \dots N.
The next M lines each consist of two space-separated integers X_i and Y_i, for i = 1 \dots M.

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 21 if P = [1, 9, 10]. Bond's total score is 30 if P = [10, 9, 1].


Comments

There are no comments at the moment.