Question: Farmer John has N ( 1 < = N < = 2 1 0 5 ) farms, numbered from 1 to N . It is
Farmer John has N
N
farms, numbered from
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 tiS
Bessie must arrive at a farm strictly before Farmer John closes it to actually visit it
Bessie has Q
Q
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 ccccN
ci
The third line consists of ttttN
ti
The next Q
lines each consist of two integers V
VN
and S
S
OUTPUT FORMAT print output to the terminal stdout:
For each of the Q
queries, output YES or NO on a new line.
SAMPLE INPUT:
SAMPLE OUTPUT:
YES
NO
YES
YES
NO
For the first query, Bessie will visit the farms at time t
so she will only get to visit farm
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
on time.
For the fourth and fifth queries, Bessie will be able to visit all but the first farm on time.
SCORING:
Inputs : NQ
Inputs : citi
Inputs : No additional constraints.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
