#P1832D2. Red-Blue Operations (Hard Version)
Red-Blue Operations (Hard Version)
No submission language available for this problem.
Description
The only difference between easy and hard versions is the maximum values of and .
You are given an array, consisting of integers. Initially, all elements are red.
You can apply the following operation to the array multiple times. During the -th operation, you select an element of the array; then:
- if the element is red, it increases by and becomes blue;
- if the element is blue, it decreases by and becomes red.
The operations are numbered from , i. e. during the first operation some element is changed by and so on.
You are asked queries of the following form:
- given an integer , what can the largest minimum in the array be if you apply exactly operations to it?
Note that the operations don't affect the array between queries, all queries are asked on the initial array .
The first line contains two integers and () — the number of elements in the array and the number of queries.
The second line contains integers ().
The third line contains integers ().
For each query, print a single integer — the largest minimum that the array can have after you apply exactly operations to it.
Input
The first line contains two integers and () — the number of elements in the array and the number of queries.
The second line contains integers ().
The third line contains integers ().
Output
For each query, print a single integer — the largest minimum that the array can have after you apply exactly operations to it.