import
java.util.ArrayList;
import
java.util.Arrays;
import
java.util.Collections;
import
java.util.Comparator;
import
java.util.HashMap;
import
java.util.Map;
class
GFG
{
static
class
Pair<K, V>
{
K first;
V second;
public
Pair(K first, V second)
{
this
.first = first;
this
.second = second;
}
public
static
<K, V> Pair<K, V> of(K first, V second)
{
return
new
Pair<>(first, second);
}
}
static
void
sweetTypeOnGivenDay(
int
a[],
int
b[],
int
n,
int
k,
ArrayList<Pair<Integer, Integer>> q)
{
ArrayList<Pair<Integer, Pair<Integer, Integer>>> v =
new
ArrayList<>();
for
(
int
i =
0
; i < n; i++)
v.add(Pair.of(b[i], Pair.of(a[i], i +
1
)));
Collections.sort(v,
new
Comparator<Pair<Integer, Pair<Integer, Integer>>>() {
@Override
public
int
compare(Pair<Integer, Pair<Integer, Integer>> a, Pair<Integer, Pair<Integer, Integer>> b) {
if
(a.first == b.first) {
if
(a.second.first == b.second.first) {
return
b.second.second - a.second.second;
}
return
b.second.first - a.second.first;
}
return
b.first - a.first;
}
});
Map<Integer, Pair<Integer, Integer>> mp =
new
HashMap<>();
int
lowerbound =
0
, upperbound =
0
;
for
(
int
i =
0
; i < n; i++) {
int
maxi_days = v.get(i).second.first;
int
mini_days = v.get(i).second.first / k;
if
(v.get(i).second.first % k !=
0
)
mini_days++;
upperbound += maxi_days;
mp.put(v.get(i).second.second, Pair.of(lowerbound, upperbound));
lowerbound += mini_days;
}
for
(
int
i =
0
; i < q.size(); i++)
{
int
x = q.get(i).first, y = q.get(i).second;
int
e = mp.get(x).first;
int
f = mp.get(x).second;
if
(y >= e && y <= f)
System.out.println(
"Yes "
);
else
System.out.println(
"No "
);
}
}
public
static
void
main(String[] args)
{
int
A[] = {
6
,
3
,
7
,
5
,
2
};
int
B[] = {
1
,
2
,
3
,
4
,
5
};
int
K =
3
;
ArrayList<Pair<Integer, Integer>> Queries =
new
ArrayList<>(
Arrays.asList(Pair.of(
4
,
4
), Pair.of(
3
,
16
), Pair.of(
2
,
7
)));
int
n = A.length;
sweetTypeOnGivenDay(A, B, n, K, Queries);
}
}