Can't figure it out!

Revision en2, by Rafi_2235, 2021-01-17 06:31:14

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


#### History

Revisions

Rev. Lang. By When Δ Comment
en2 Rafi_2235 2021-01-17 06:31:14 18
en1 Rafi_2235 2021-01-17 06:30:18 917 Initial revision (published)