Woburn Challenge 2018-19 Round 3 - Senior Division
Jessie's been training hard, and is ready to go out there and claim some new Pokémon for Team Rocket fair and square! Or at least, by beating some Pokémon trainers in battles fair and square, and then proceeding to steal their Pokémon.
Jessie has Pokémon at her disposal, with the -th one having two traits of interest — a Strength of and a Speed of .
She'll be battling against trainers, one after another, each with a single Pokémon. In each battle, Jessie will choose one of her Pokémon to use in it. There are no restrictions regarding her choices — for example, she may choose to use any of her Pokémon either in multiple battles, or not at all.
Each trainer's Pokémon is vulnerable against the Strength and Speed traits to various degrees, based on the values and . Battle Effectiveness is a measure of how effective Jessie's chosen Pokémon is against a trainer's Pokémon. If Jessie chooses to use her -th Pokémon in the -th battle, the resulting Battle Effectiveness will be .
For each of the battles, help Jessie determine the maximum possible Battle Effectiveness that she can achieve by choosing an optimal Pokémon to use. Please note that the answer may not fit within a -bit signed integer.
Subtasks
In test cases worth of the points, and .
Input Specification
The first line of input consists of a single integer, .
lines follow, the -th of which consists of two space-separated
integers, and , for .
The next line consists of a single integer, .
lines follow, the -th of which consists of two space-separated
integers, and , for .
Output Specification
lines, the -th of which is the maximum Battle Effectiveness which Jessie can achieve in the -th battle.
Sample Input
2
1 10
8 2
2
10 1
1 10
Sample Output
82
101
Sample Explanation
In the first battle, Jessie should use her second Pokémon for a Battle Effectiveness of . In the second battle, she should instead use her first Pokémon for a Battle Effectiveness of .
Comments