Help me in solving AMMEAT problem

My issue

I think i solved this problem correctly but its shows some error when i can submit my code, so please you guys suggest me how can i improve my code so that it passes all the test cases.

My code

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

int main() {
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        vector<int> plates(n);
        for(int i=0; i<n; ++i){
            cin>>plates[i];
        }
        sort(plates.begin(), plates.end(), greater<int>());
        int platesNeeded=0;
        int totalMeatballs=0;
        for(int i=0; i<n; ++i){
            totalMeatballs += plates[i];
            platesNeeded++;
            if(totalMeatballs >= m){
                cout<<platesNeeded<<endl;
                break;
            }
        }
        if(totalMeatballs < m){
            cout<<-1<<endl;
        }
    }
}

Learning course: Sorting using C++
Problem Link: Andrew and the Meatballs Practice Problem in - CodeChef

@smd397452
use long long int instead of int to avoid integer overflow