My issue
My code
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
void solve() {
int t;
cin >> t;
while (t--)
{
ll n, q;
cin >> n >> q;
ll arr[n];
for(int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr+n);
vector<ll> v(n);
for(int i = 0; i < n; i++) {
v[i] = ((n-i-1) * (n-i-2)) / 2;
if(i > 0) v[i] += v[i-1];
}
while(q--) {
int m;
cin >> m;
cout << arr[lower_bound(v.begin(), v.end(), m) - v.begin()] << endl;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
solve();
return 0;
}
Problem Link: TRIPLETMIN Problem - CodeChef