Learning course: Sorting using C++
Problem Link: CodeChef: Practical coding for everyone
Feedback
include
using namespace std;
#include<bits/stdc++.h>
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n,m;
cin>>n>>m;
vector a(n);
for(int i=0;i<n;i++)
cin>>a[i];
sort(a.begin(),a.end());
long long int i,temp=0,sum=0;
int count=0;
for( i=n-1;i>=0;i--)
{
count++;
sum=sum+a[i];
if(sum>=m)
{
temp=1;
break;
}
}
if(temp==0)
cout<<"-1"<<endl;
else
cout<<count<<endl;
}
return 0;
}
WHY THIS HAS NOT BE ACCEPTED IN CODECHEFF(IT SHOWS WRONG ANSWER)