Andrew and the Meatballs | CodeChef

solution: CodeChef: Practical coding for everyone
getting WA.
Can someone help?

You need to make the variables “tem” and “i” as long long and in the sorting make it “greater<long long>”
This is the working code:

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	
	while (t--)
	{
	    vector <long long int> a;
	    int n,sum=0;
	    long long tem;
	    long long m,temo;
	    cin>>n>>m;
	    int flag=0;
	    temo=m;
	    for (int i=0;i<n;i++)
	    {
	        cin>>tem;
	        a.push_back(tem);
	        temo-=tem;
	        if (flag==0 && temo<=0)
	           flag=1;
	    }
	    if (flag==0)
	       cout<<"-1\n";
	    else
	    {   long long i=0;
	        sort(a.begin(),a.end(), greater <long long>());
	        while (m>0)
	        {
	            m-=a[i];
	            i++;
	        }
	        cout<<i<<endl;
	    }
	}
	return 0;
}

thank you :slight_smile: :slight_smile: