ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules

2188. They are charging the cannon... WHY?!

Time limit: 1.0 second
Memory limit: 256 MB
The Hispaniola has finally approached Treasure Island! The pirates’ boat has already set off towards the island and has drifted away from the ship by D feet. Jim’s boat has just been launched into the water and is at the same point as the ship.
For the next n seconds, both boats will move in a straight line towards the island. Jim knows exactly that in the i-th second, the pirates’ boat will move towards the island by bi feet. At the same time, in the i-th second, Jim’s boat can move towards the island by any integer number of feet from 0 to ai at Jim’s discretion. Assume that during each second both boats move uniformly.
Jim wants to overtake the pirates’ boat as soon as possible so that after that the pirates will never catch up with Jim. Formally, let t (1 ≤ tn) be the smallest second number such that at the end of it Jim’s boat is strictly closer to the island than the pirates’ boat. Jim wants to ensure that starting from this moment and until the end of the n-th second, his boat is strictly closer to the island than the pirates’ boat. Out of all possible t, he wants to choose the smallest one.
However, Jim does not know the distance D exactly. He has q assumptions d1, d2, …, dq about what D could be. He wants to know the smallest possible number t for each of his assumptions.
Problem illustration

Input

The first line contains two integers n and q — the number of seconds and the number of Jim’s assumptions (1 ≤ n ≤ 105, 1 ≤ q ≤ 105).
The second line contains n integers a1, a2, …, an — the maximum possible distances that Jim’s boat can travel in each second (0 ≤ ai ≤ 109).
The third line contains n integers b1, b2, …, bn — the distances that the pirates’ boat will travel (0 ≤ bi ≤ 109).
The fourth line contains q integers d1, d2, …, dq — the assumed initial distances of the pirates’ boat from the ship (1 ≤ di ≤ 109).

Output

In q lines, output one integer — the answer to each of Jim’s assumptions.
If Jim can overtake the pirates at the end of second t such that the pirates will never catch him, output the number t (1 ≤ tn). Out of all suitable numbers t, output the smallest one. If Jim’s plan is impossible to execute, output −1.

Samples

inputoutput
10 10
7 4 7 0 5 6 4 4 5 4
5 3 5 1 2 3 3 7 2 0
1 2 3 4 5 6 7 8 14 15
1
2
3
5
5
5
6
10
10
-1
1 4
4
1
1 2 3 4
1
1
-1
-1
Problem Author: Artyom Kutuzov
Problem Source: Ural School Programming Contest 2024