The link to the question.
I cant understand why the following solution is wrong
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int long long
int n,b,arr[100000];
int main()
{
IOS;
int t; cin>>t;
int tc=0;
while(t--)
{
tc++;
//int n;
cin>>n;
//int b;
cin>>b;
//int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
int sum=0;
for(int i=0;i<n;i++)
{
//sum+=arr[i];
if(b>=arr[i])
b-=arr[i];
else
{
cout<<"Case #"<<tc<<": "<<i<<"\n";
break;
}
}
}
}
but the this code with minor change is right
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#define int long long
int n,b,arr[100000];
int main()
{
IOS;
int t; cin>>t;
int tc=0;
while(t--)
{
tc++;
//int n;
cin>>n;
//int b;
cin>>b;
//int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
int sum=0;
int ans=0;
for(int i=0;i<n;i++)
{
//sum+=arr[i];
if(b>=arr[i])
{
b-=arr[i];
ans++;
}
}
cout<<"Case #"<<tc<<": "<<ans<<"\n";
}
}