MAGCARI

huge_array

Mar 6th, 2023
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. /*
  2.     Task    : _example
  3.     Author  : Phumipat C. [MAGCARI]
  4.     Language: C++
  5.     Created : 06 March 2023 [19:47]
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. pair<int ,int > a[100010];
  10. int b[100010];
  11. int main(){
  12.     cin.tie(0)->sync_with_stdio(0);
  13.     cin.exceptions(cin.failbit);
  14.     int n,q;
  15.     cin >> n >> q;
  16.     for(int i=1;i<=n;i++)
  17.         cin >> a[i].first >> a[i].second;
  18.     sort(a+1,a+n+1);
  19.     for(int i=1;i<=n;i++){
  20.         a[i].second+=a[i-1].second;
  21.         b[i] = a[i].second;
  22.     }
  23.     while(q--){
  24.         int idx;
  25.         cin >> idx;
  26.         int pos = lower_bound(b+1,b+n+1,idx)-b;
  27.         cout << a[pos].first << '\n';
  28.     }
  29.     return 0;
  30. }
  31. /*
  32. (3,4), (4,2), (10,2)
  33. (3,4), (4,6), (10,8)
  34. 1      2      3
  35.  
  36. */
Advertisement
Add Comment
Please, Sign In to add comment