fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5.  
  6.  
  7.  
  8.  
  9. int main() {
  10.  
  11. ios_base::sync_with_stdio(false);
  12.  
  13. cin.tie(NULL);
  14.  
  15. int N, Q;
  16.  
  17. cin >> N >> Q;
  18.  
  19.  
  20.  
  21. vector<int> timeleft(N);
  22.  
  23. int tmp=0;
  24.  
  25. for (int i = 0; i < N; ++i) cin >> timeleft[i]; //input close time
  26.  
  27. for (int i = 0; i < N; ++i) {
  28.  
  29. cin >> tmp; // t, traveling time to get to farm
  30.  
  31. timeleft[i] -= tmp; //closetime-t, s+t<c, so s<c-t, only keep how many time left to close time
  32.  
  33. }
  34. sort(timeleft.begin(), timeleft.end());
  35. while(Q--){
  36. int v,s;cin>>v>>s;
  37. auto it = upper_bound(timeleft.begin(),timeleft.end(), s);
  38. int idx=distance(timeleft.begin(), it);
  39. (timeleft.size()-idx>=v) ? cout<<"YES"<<endl : cout<<"NO"<<endl;
  40. }
  41.  
  42. }
  43.  
  44.  
  45.  
  46.  
  47.  
Success #stdin #stdout 0.01s 5320KB
stdin
5 5
3 5 7 9 12
4 2 3 3 8
1 5
1 6
3 3
4 2
5 1
stdout
YES
NO
YES
YES
NO