Help me in solving TRIPLETMIN problem

My issue

Only giving correct answer on first and second test case

My code

// Problem: Triplets Min
// Contest: CodeChef - START97C
// URL: https://www.codechef.com/START97C/problems/TRIPLETMIN
// Memory Limit: 256 MB
// Time Limit: 1000 ms

#include <bits/stdc++.h>
#define pr(a) cout << a << endl
#define fr(i, n) for (i = 0; i < n; ++i)
#define fri(i, k, n) for (i = k; i <= n; ++i)
#define frr(i, k) for (i = n - 1; i >= 0; --i)
#define y cout<<"YES"<<endl
#define n cout<<"NO"<<endl

using namespace std;

void solve()
{
 int  b, c=0, d, e, p = 0, s = 0, i=0,f;
    cin >> b>>c;
    vector<int>v;
    
    fr(i,b){
    	cin>>d;
    	v.push_back(d);
    }
    i=0;
     vector<int>qu;
     fr(i,c){
    	cin>>d;
    	qu.push_back(d);
    }
  sort(v.begin(),v.end());
   i=0;
   int pre=0;
   f=v.size()-2;
   
   
  vector<int>st;
    fr(i,f){
    	int val=((v.size()-i-2)*(v.size()-i-1))/2;
    	pre+=val;
    	st.push_back(pre);
    }
    
     for(int i=0;i<c;i++){
   	   auto it=lower_bound(st.begin(),st.end(),qu[i]);
   	   int in=it-st.begin();
   	   cout<<v[in]<<endl;
     }
   }

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tc ;
    cin>>tc;

    for (int t = 1; t <= tc; t++)
    {

        solve();
    }
}

Problem Link: TRIPLETMIN Problem - CodeChef

You have to take all integers in long long, your values get overflowed in sum and might be in query also.
Hope it might be useful.

Not working now also brother

Use these two changes extra in your program,
1- Add define int long long
2- Change int main() to signed main()

include <bits/stdc++.h>
define pr(a) cout << a << endl
define fr(i, n) for (i = 0; i < n; ++i)
define fri(i, k, n) for (i = k; i <= n; ++i)
define frr(i, k) for (i = n - 1; i >= 0; --i)
define y cout<<“YES”<<endl
define n cout<<“NO”<<endl
define int long long
using namespace std;

void solve()
{
int b, c=0, d, e, p = 0, s = 0, i=0,f;
cin >> b>>c;
vectorv;

fr(i,b){
	cin>>d;
	v.push_back(d);
}
i=0;
 vector<int>qu;
 fr(i,c){
	cin>>d;
	qu.push_back(d);
}

sort(v.begin(),v.end());
i=0;
int pre=0;
f=v.size()-2;

vectorst;
fr(i,f){
int val=((v.size()-i-2)*(v.size()-i-1))/2;
pre+=val;
st.push_back(pre);
}

 for(int i=0;i<c;i++){
   auto it=lower_bound(st.begin(),st.end(),qu[i]);
   int in=it-st.begin();
   cout<<v[in]<<endl;
 }

}

signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tc ;
cin>>tc;

for (int t = 1; t <= tc; t++)
{

    solve();
}

}