#P10189. Bessie's Farm Visits
Bessie's Farm Visits
Bessie's Farm Visits
Farmer John owns N farms numbered from 1 to N. For each farm i, Farmer John will close the farm at time \( c_i \). Each farm i has a travel time \( t_i \). Bessie wakes up at time \( S \) and plans to visit farm i exactly at time \( S+t_i \). She can successfully visit a farm only if she arrives strictly before the closing time of that farm; that is, if and only if
[ S+t_i < c_i ]
Equivalently, if we define \( d_i = c_i-t_i \), the condition for a successful visit is \( S < d_i \). Bessie wishes to maximize her daily productivity by visiting as many farms as possible before they close.
You are given Q queries. In each query, Bessie provides two integers \( S \) and \( V \). For each query, determine whether, if Bessie wakes up at time \( S \), she can successfully visit at least \( V \) farms.
Note: It is not possible to change the visiting times. Each farm \( i \) is visited at the fixed time \( S+t_i \).
inputFormat
The first line contains an integer N \( (1 \le N \le 2 \cdot 10^5) \) representing the number of farms.
The second line contains N space-separated integers \( t_1, t_2, \ldots, t_N \) representing the travel time to each farm.
The third line contains N space-separated integers \( c_1, c_2, \ldots, c_N \) where \( c_i \) is the closing time of the i-th farm.
The fourth line contains an integer Q \( (1 \le Q \le 2 \cdot 10^5) \) representing the number of queries.
Each of the next Q lines contains two integers \( S \) and \( V \). \( S \) is the time Bessie wakes up and \( V \) is the target number of farms she wants to visit.
outputFormat
For each query, output a single line containing YES
if Bessie can visit at least \( V \) farms, or NO
otherwise.
sample
3
1 2 3
5 6 10
3
0 3
4 2
3 2
YES
NO
YES
</p>