Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- #define pb push_back
- int main()
- {
- _test
- {
- int n, q;
- cin>>n>>q;
- vector<int> a(n);
- for(auto &e: a) cin>>e;
- sort(a.begin(), a.end());
- vector<ll int> cnt(n);
- for(int i=0; i<n; i++)
- {
- ll int x = n-i-1;
- cnt[i] = (x*(x-1))/2;
- }
- for(int i=1; i<n; i++)
- cnt[i] += cnt[i-1];
- while(q--)
- {
- ll int k;
- cin>>k;
- int pos = lower_bound(cnt.begin(), cnt.end(), k) - cnt.begin();
- cout<<a[pos]<<"\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment