Help me in solving AMMEAT problem

My issue

what is wrong

My code

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
 int t,n,m;
    cin>>t;
    while (t--)
    {
        cin>>n>>m;
        int a[n];
        for (int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int count=0,ans=0,i=0;
        for ( i = n-1; i >= 0; i--)
        {
           if (ans>=m)
           {
               break;
           }
           
               ans+=a[i];
               count++;
           
            
        }
        
        if (ans>=m)
        {
            cout<<count<<endl;
        }
        else
            cout<<-1<<endl;
            }

    return 0;
}

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

include
include
using namespace std;

int main()
{
long t, n, m;
cin >> t;
while (t–)
{
cin >> n >> m;
long a[n];
for (long i = 0; i < n; i++)
{
cin >> a[i];
}
sort(a, a + n);
long count = 0, ans = 0, i = 0;

    for (i = n - 1; i >= 0; i--)
    {
        if (ans >= m)
        {
            break;
        }
        ans += a[i];
        count++;
    }

    if (ans >= m)
    {
        cout << count << endl;
    }
    else
        cout << -1 << endl;
}

return 0;

}
i dont know why but they like long not int