Orig Description
Score : 900 points
Problem StatementAlice lives on a line. Today, she will travel to some place in a mysterious vehicle.
Initially, the distance between Alice and her destination is D. When she input a number x to the vehicle, it will travel in the direction of the destination by a distance of x if this move would shorten the distance between the vehicle and the destination, and it will stay at its position otherwise. Note that the vehicle may go past the destination when the distance between the vehicle and the destination is less than x.
Alice made a list of N numbers. The i-th number in this list is d_i. She will insert these numbers to the vehicle one by one.
However, a mischievous witch appeared. She is thinking of rewriting one number in the list so that Alice will not reach the destination after N moves.
She has Q plans to do this, as follows:
Rewrite only the q_i-th number in the list with some integer so that Alice will not reach the destination.
Write a program to determine whether each plan is feasible.
Constraints
1≤ N ≤ 5*10^5
1≤ Q ≤ 5*10^5
1≤ D ≤ 10^9
1≤ d_i ≤ 10^9(1≤i≤N)
1≤ q_i ≤ N(1≤i≤Q)
D and each d_i are integers.
InputInput is given from Standard Input in the following format:
N D
d_1 d_2 ... d_N
Q
q_1 q_2 ... q_Q
OutputPrint Q lines. The i-th line should contain YES if the i-th plan is feasible, and NO otherwise.
Sample Input 14 10
3 4 3 3
2
4 3
Sample Output 1NO
YES
For the first plan, Alice will already arrive at the destination by the first three moves, and therefore the answer is NO.
For the second plan, rewriting the third number in the list with 5 will prevent Alice from reaching the destination as shown in the following figure, and thus the answer is YES.
Sample Input 25 9
4 4 2 3 2
5
1 4 2 3 5
Sample Output 2YES
YES
YES
YES
YES
Alice will not reach the destination as it is, and therefore all the plans are feasible.
Sample Input 36 15
4 3 5 4 2 1
6
1 2 3 4 5 6
Sample Output 3NO
NO
YES
NO
NO
YES
Extracted Specification
An integer N (1 ≤ N ≤ 5*10^5), representing some quantity or size.
An integer D (1 ≤ D ≤ 10^9), representing another quantity or size.
A list of N integers, where each integer is between 1 and 1e9.
An integer Q (1 ≤ Q ≤ 5*10^5), representing another quantity or size.
A list of Q integers, where each integer is between 1 and N.
### Example Input:
```
4 10
3 4 3 3
2
4 3
```
### Function Signature:
Write a function f(N, D, A, Q, B) that takes in the input.
def f(N: int, D: int, A: List[int], Q: int, B: List[int]):
'''
N: an integer
D: an integer
A: a list of integers
Q: an integer
B: a list of integers
'''
Test Case Generator
Sure, here's a test case generator for the given problem statement:
```python
import random
def tcgen():
# Generate values for N and D within the given constraints
N = random.randint(1, 5 * 10**5)
D = random.randint(1, 10**9)
# Generate the list of distances d_i
d = [random.randint(1, 10**9) for _ in range(N)]
# Generate the number of plans Q
Q = random.randint(1, 5 * 10**5)
# Generate the list of positions q_i to be rewritten
q = [random.randint(1, N) for _ in range(Q)]
return N, D, d, Q, q
# Example usage:
N, D, d, Q, q = tcgen()
print(N, D)
print(" ".join(map(str, d)))
print(Q)
print(" ".join(map(str, q)))
```
The `tcgen` function generates random test cases within the provided constraints:
1. `N` - the number of distances input to the vehicle.
2. `D` - the initial distance between Alice and her destination.
3. `d` - a list of distances Alice will input to the vehicle.
4. `Q` - the number of plans the witch has.
5. `q` - a list of positions in the list `d` that the witch may rewrite.
You can use this function to generate test cases for your problem.
Extract Arguments
def extract_arguments(fh):
N, D = map(int, fh.readline().strip().split())
d = list(map(int, fh.readline().strip().split()))
Q = int(fh.readline().strip())
q = list(map(int, fh.readline().strip().split()))
return N, D, d, Q, q