数据范围2e5,考虑nlogn
我们发现t+s<c,即s<c-t,也就是看a数组中有多少严格大于s的数,(这个可以用二分来实现,也可以使用upper_bound)
如果个数>=v,则可以;否则则不可以。
对于样例1
c: 3 5 7 9 12
t: 4 2 3 3 8
而二分需要有序的前提,所以需要排序
对于排序后的a
a:-1 3 4 4 6
const int N = 2e5 + 10,T = 20;
int n,m,v,s;
LL c[N],t[N],a[N];
void solve()
{
cin >> n >> m;
for (int i = 1;i <= n; i++) cin >> c[i];
for (int i = 1;i <= n; i++) cin >> t[i];
for (int i = 1;i <= n; i++) a[i] = c[i] - t[i];
sort(a + 1,a + 1 + n);
while(m --)
{
cin >> v >> s;
int pos = upper_bound(a + 1,a + 1 + n,s) - (a);//pos就是第一个大于s的数的下标,1~n
// cout << pos << "==" << endl;
if ((n - pos + 1) >= v) cout << "YES" << endl;//n-pos+1就是大于s的数的个数
else cout << "NO" << endl;
}
}