## DMOPC '18 Contest 6 P4 - Tank

View as PDF

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

Author:
Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 units is the best tank. Each unit has two corresponding defensive traits: defense and resistance. Defense, represented as , mitigates physical attacks. Resistance, represented as , mitigates magical attacks. More precisely, the amount of damage a unit takes from a physical attack is and the amount of damage a unit takes from a magical attack is .

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

#### Input Specification

The first line will contain three space-separated integers, , , .
The next lines will each contain two space-separated integers, and , representing the defense stat and resistance stat of the unit.
The following line will contain space-separated integers, , representing the physical attacks.
The final line will contain space-separated integers, , 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

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

#### Sample Output 1

3

#### Explanation for Sample 1

Kiran's first unit will take damage from the physical attacks and damage from the magical attacks, resulting in total damage. Kiran's second unit will take damage from the physical attacks and damage from the magical attacks, resulting in total damage. Kiran's third unit will take damage from the physical attacks and damage from the magical attacks, resulting in damage. So Kiran should use his third unit.

#### Sample Input 2

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

#### Sample Output 2

3

#### Explanation for Sample 2

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