My issue
what’s wrong in code
My code
#include<bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
int T;
cin>>T;
while(T--){
int N,M;
cin>>N>>M;
vector<long long>packets(N);
for(int i=0;i<N;i++){
cin>>packets[i];
}
sort(packets.begin(),packets.end(),greater<long long>());
long long sum=0;
int count=0;
bool possible=false;
for(int i=0;i<N;i++){
sum+=packets[i];
count++;
if(sum>=M){
possible=true;
break;
}
}
if(possible){
cout<<count<<endl;
}
else{
cout<<"-1"<<endl;
}
}
return 0;
}
Learning course: Chitkara DSA Bootcamp
Problem Link: CodeChef: Practical coding for everyone