Question: Farmer John has N ( 1 < = N < = 2 1 0 5 ) farms, numbered from 1 to N . It is

Farmer John has N
(1<=N<=2105
) farms, numbered from 1
to N
. It is known that FJ closes farm i
at time ci
. Bessie wakes up at time S
, and wants to maximize the productivity of her day by visiting as many farms as possible before they close. She plans to visit farm i
on time ti+S
. Bessie must arrive at a farm strictly before Farmer John closes it to actually visit it.
Bessie has Q
(1<=Q<=2105)
queries. For each query, she gives you two integers S
and V
. For each query, output whether Bessie can visit at least V
farms if she wakes up at time S
.
INPUT FORMAT (input arrives from the terminal / stdin):
The first line consists of N
and Q
.
The second line consists of c1,c2,c3...cN
(1<=ci<=106
).
The third line consists of t1,t2,t3...tN
(1<=ti<=106
).
The next Q
lines each consist of two integers V
(1<=V<=N
) and S
(1<=S<=106
).
OUTPUT FORMAT (print output to the terminal / stdout):
For each of the Q
queries, output YES or NO on a new line.
SAMPLE INPUT:
55
357912
42338
15
16
33
42
51
SAMPLE OUTPUT:
YES
NO
YES
YES
NO
For the first query, Bessie will visit the farms at time t=[9,7,8,8,13]
, so she will only get to visit farm 4
on time before FJ closes the farm.
For the second query, Bessie will not be able to visit any of the farms on time.
For the third query, Bessie will visit farms 3,4,5
on time.
For the fourth and fifth queries, Bessie will be able to visit all but the first farm on time.
SCORING:
Inputs 2-4: N,Q<=103
Inputs 5-9: ci,ti<=20
Inputs 10-17: No additional constraints.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!