DMOPC '18 Contest 6 P4 - Tank

View as PDF

Submit solution


Points: 10
Time limit: 2.5s
Memory limit: 256M

Author:
Problem type

Kiran is playing a tactical RPG! His signature move is to field a tanky unit, end the turn, and watch all the enemies fail to kill it. He wants to figure out which of his N units is the best tank. Each unit has two corresponding defensive traits: defense and resistance. Defense, represented as ui, mitigates physical attacks. Resistance, represented as vi, mitigates magical attacks. More precisely, the amount of damage a unit takes from a physical attack is max(AttDef,0) and the amount of damage a unit takes from a magical attack is max(AttRes,0).

In the next battle, Kiran will need his tank to survive against P physical attacks and M magical attacks. The ith physical attack will have attack stat ai and the jth magical attack will have attack stat bj. Help Kiran determine which of his units will take the least total amount of damage.

Constraints

1ui,vi,ai,bi1000000
1N,P,M200000

Input Specification

The first line will contain three space-separated integers, N, P, M.
The next N lines will each contain two space-separated integers, ui and vi, representing the defense stat and resistance stat of the ith unit.
The following line will contain P space-separated integers, a1,a2,,aP, representing the physical attacks.
The final line will contain M space-separated integers, b1,b2,,bM, representing the magical attacks.

Output Specification

Output the index of the best tank for the next battle. If there are ties, output the smallest index.

Sample Input 1

Copy
3 4 2
40 32
37 29
33 41
33 42 36 39
48 45

Sample Output 1

Copy
3

Explanation for Sample 1

Kiran's first unit will take 0+2+0+0=2 damage from the physical attacks and 16+13=29 damage from the magical attacks, resulting in 31 total damage. Kiran's second unit will take 0+5+0+2=7 damage from the physical attacks and 19+16=35 damage from the magical attacks, resulting in 42 total damage. Kiran's third unit will take 0+9+3+6=18 damage from the physical attacks and 7+4=11 damage from the magical attacks, resulting in 29 damage. So Kiran should use his third unit.

Sample Input 2

Copy
4 3 3
37 26
37 19
40 24
38 26
51 47 50
62 43 46

Sample Output 2

Copy
3

Explanation for Sample 2

The total damage to each unit is 110, 131, 107, and 107 respectively. There is a tie between the third and fourth unit, so the smaller index, 3 is the answer.


Comments