Pls Help me in finding edge case on which I am getting wrong and answer

My issue

My code

#include <bits/stdc++.h>
#define endl "\n"
#define Y cout<<"YES"<<endl
#define N cout<<"NO"<<endl
using namespace std;
int nc2(int n)
{
    return n*(n-1)/2;
}
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,q;
        cin>>n>>q;
        int a[n];
        for(int i=0;i<n;i++)
        cin>>a[i];
        sort(a,a+n);
        int k[q];
        for(int i=0;i<q;i++)
        cin>>k[i];
        for(int i=0;i<q;i++)
        {
            int x=k[i];
            int c=1;
            while(x>0)
            {
                int s=nc2(n-c);//since no.of triplet array with kth smallest element will be (n-1)C2,(n-2)C2,......2C2
                if(s>=x)
                {
                    cout<<a[c-1]<<endl;
                    break;
                }
                else
                {
                    c++;
                    x-=s;
                }
            }
        }
    }
}

Problem Link: TRIPLETMIN Problem - CodeChef

Use long long everywhere .
This method will anyways give TLE.
We need to use binary search or lowerbound() function, because queries can be large in numbers

brp but I have used # define int long long above
also I am not getting tle ,I am getting wrong answer