### Rafi_2235's blog

By Rafi_2235, history, 4 months ago,

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;
}


• -18

 » 4 months ago, # |   0 int a=0; int sm=0; while(sm+ar[a]<=b && a
•  » » 4 months ago, # ^ |   0 thank you very much
 » 4 months ago, # |   0 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.