一道比较简单的二分题。
我们只需要求出 Bessie 想要到达农场 i i i 最多能容忍的时间(即题目中的 S S S 减去 1 1 1) a i a_i ai,然后把它从小到大排序,在每次询问里面二分即可。
考场代码如下:
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef long long ll;
typedef pair<int, int> pr;
#define up(l, r, i) for(int i = (l); i <= (r); i++)
#define down(r, l, i) for(int i = (r); i >= (l); i--)
const int mod = 1000000007;
const int base = 2333;
const double eps = 1e-6;
inline int read() {
int x = 0, f = 1; char ch = getchar();
while(ch < '0' || ch > '9') { if(ch == '-') f = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
return x * f;
}
int n, m, k, Q, T, _, ans = 0;
int c[1000007];
int t[1000007];
int a[1000007];
signed main() {
n = read(), Q = read();
for(int i = 1; i <= n; i++) c[i] = read();
for(int i = 1; i <= n; i++) t[i] = read(), a[i] = c[i] - t[i] - 1;
sort(a + 1, a + n + 1);
// for(int i = 1; i <= n; i++) cout << a[i] << " ";
// cout << "\n";
while(Q--) {
int V = read(), S = read();
// cout << "lower_bound: " << (lower_bound(a + 1, a + n + 1, S) - a - 1) << "\n";
int cnt = n - (lower_bound(a + 1, a + n + 1, S) - a - 1);
if(cnt >= V) printf("YES\n");
else printf("NO\n");
}
return 0;
}