Help me in solving AMMEAT problem

My issue

Hi community, when my code is submitted, I always get a WA, but nothing seems to be wrong, even the few mistakes that the debugger gave me.

My code

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

int main() {
	int t;
	cin >> t;
	while (t--)
	{
	    int n, m;
	    cin >> n >> m;
	    int a[n];
	    for (int i = 0; i < n; i++)
	    {
	        cin >> a[i];
	    }
	    sort(a, a + n, greater<int>()); // to sort the array in descending order
	    int d=0, tot=0;
	    for (int i = 0; i < n; i++) {
            tot += a[i];
            if (tot >= m) {
                d = i + 1;
                break;
            }
        }
	    cout << ((d==0)?-1:d) << endl;
	}
	return 0;
}

Learning course: Sorting using C++
Problem Link: CodeChef: Practical coding for everyone

@alexanderchew
constraints is high
use long long int
i have corrected it in your code

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

int main() {
	int t;
	cin >> t;
	while (t--)
	{
	    long long int n, m;
	    cin >> n >> m;
	    long long  int a[n];
	    for (int i = 0; i < n; i++)
	    {
	        cin >> a[i];
	    }
	    sort(a, a + n, greater<long long int>()); // to sort the array in descending order
	    long long int d=0, tot=0;
	    for (int i = 0; i < n; i++) {
            tot += a[i];
            if (tot >= m) {
                d = i + 1;
                break;
            }
        }
	    cout << ((d==0)?-1:d) << endl;
	}
	return 0;
}

Ok thanks