I have typed the following code for the warrior problem.THe program runs fine for custom inputs.But it gives a runtime TLE(Time Limit Exceeded) error when i submit it.Please suggest some solutions and corrections
#include
#include
#include
using namespace std;
int main()
{
vector a;
vector quer;
vector ans;
long int n,summa,cnt=0,q,s;
int t;
cin>>t;
for(int p=0;p<t;p++)
{
cin>>n;
cin>>q;
for(long int i=0;i<n;i++)
{
cin>>summa;
a.push_back(summa);
}
std::sort(a.begin(),a.end());
for(long int i=0;i<q;i++)
{
cin>>summa;
quer.push_back(summa);
}
for(long int k=0;k<q;k++)
{
long int i=0;
cnt=0;
s=quer[k];
while(s>a[i]&&i<n)
{
s=2*(s-a[i]);
i++;
cnt++;
}
ans.push_back(cnt);
}
for(long int i=0;i<q;i++)
{
cout<<ans[i]<<"\n";
}
}
return 0;
}