Help me in solving PUSH7PA problem...please explain it ,i am unable to think its solution

My issue

My code

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

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    long int n;
	    cin>>n;
	   long int h[n];
	    for( long int i=0;i<n;i++){
	        cin>>h[i];
	    }
	  sort(h,h+n);
	  
	    
	}
	    
	return 0;
}

Problem Link: PUSH7PA Problem - CodeChef

@deepak_5047
Ok here a hint
suppose
u got an array with same values like 3 3 3
what will be the maximum height u can reach its the 3+frequency of 3 -1=3+3-1=5;