Learning course: Sorting using C++
Problem Link: CodeChef: Practical coding for everyone
Feedback
include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n,m;
cin>>n>>m;
int p[n];
for(int i=0;i<n;i++){
cin>>p[i];
}
sort(p,p+n);
int sum = 0;
int flag = 0;
for(int i=0;i<n;i++){
sum+=p[n-i-1];
if(sum>=m){
cout<<i+1<<endl;
flag = 1;
break;
}
}
if(flag==0){
cout<<-1<<endl;
}
}
return 0;
}
When run on each test case individually, your code appears to be correct. However, when run on the entire test file, it returns a WA. The most common reasons for this are that you do not have a newline after each test case, or you do not reinitialize some variables in each test case. Getting this error for above code for Andrew and the Meatballs please help me fix this issue