Hello guys, Recently I was trying to take preparation for google kickstart. And while solving a problem of kickstart-2020 I faced a problem with my solution. I was able to pass the sample tests but I was getting WA in test set 1. Can anyone please help me figure out the problem with my code. Here is my code-
#include <bits/stdc++.h>
using namespace std;
int solve(){
int n,b;
cin>>n>>b;
int ar[n];
for(int i=0;i<n;i++){
cin>>ar[i];
}
sort(ar,ar+n);
int a=0;
int sm=ar[0];
while(sm<=b){
a+=1;
sm+=ar[a];
}
return a;
}
int main(){
int t,i=1;
cin>>t;
while(t--){
int ans=solve();
cout<<"Case #"<<i<<": "<<ans<<'\n';
i++;
}
return 0;
}
*The problem link-- https://codingcompetitions.withgoogle.com/kickstart/round/000000000019ffc7/00000000001d3f56
Consider a case where B=100000 and A = [1,2,3,4,5].
Also just fyi, it often helps for you to explain the thinking behind your code since that makes it easier for others to debug.