fork download
  1. // ~~ icebear ~~
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int MOD = 1e9 + 7;
  6. const int inf = 1e9 + 27092008;
  7. const long long INF = 1e18 + 27092008;
  8. const int N = 2e5 + 5;
  9. int n, q;
  10. pair<int, int> a[N];
  11. long long pref[N];
  12.  
  13. int main() {
  14. ios_base::sync_with_stdio(0);
  15. cin.tie(0); cout.tie(0);
  16. cin >> n >> q;
  17. for(int i = 1; i <= n; i++) cin >> a[i].second >> a[i].first;
  18. sort(a + 1, a + n + 1);
  19. for(int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i].second;
  20. while(q--) {
  21. long long k;
  22. cin >> k;
  23. int pos = lower_bound(pref + 1, pref + n + 1, k) - pref;
  24. cout << a[pos].first << '\n';
  25. }
  26. return 0;
  27. }
Success #stdin #stdout 0.01s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty