AcWing 5540. 最大限度地提高生产力
原题链接
简单
作者:
懒惰的蚩蚩
,
2024-11-06 19:59:19
,
所有人可见
,
阅读 9
排序+二分
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 15;
int c[N], t[N], ct[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
for(int i = 1; i <= n; i++) {
cin >> c[i];
}
for(int i = 1; i <= n; i++) {
cin >> t[i];
ct[i] = c[i] - t[i];
}
sort(ct + 1, ct + 1 + n);
// for(int i = 1; i <= n; i++) {
// cout << ct[i] << " ";
// }
// cout << endl;
while(q--) {
int v, s;
cin >> v >> s;
int l = 1, r = n;
while(l < r) {
int mid = l + r >> 1;
if(ct[mid] > s) r = mid;
else l = mid + 1;
}
// cout << l << endl;
if(ct[l] <= s) l++;
if(v <= n - l + 1) cout << "YES" << endl;
else cout << "NO" << endl;
}
return 0;
}