Help me in solving BLDST problem

My issue:plz explain why my logic does not work. I have noticed the min balls of a particular element i.e the min element of array and the ans would be min element -1 since the no of boxes>=the max element of the array.

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[m];
	    for(int i=0;i<n;i++){
	        cin>>a[i];
	    }
	    cout<<*min_element(a,a+m)-1<<endl;
	}
	// your code goes here
	return 0;
}

Problem Link: BLDST Problem - CodeChef

@aastha_ojha204
for ex-
1
5 3
5 2 2
your code will give 1 as output but it will be 0
1 2
1 2
1 3
1 3
1
see the above arrangement none of the box have M balls 4 of them have 2 balls and 1 have only 1 ball