Dividing Array Problem

one of the test case is giving tle

@2018kucp1041

while(v.size() != 0){
		ll max = *max_element(v.begin(), v.end());
		v.erase(max_element(v.begin(), v.end()));
		ll min = *max_element(v.begin(), v.end());
		v.erase(max_element(v.begin(), v.end()));
        sum += (max-min);
	}

Complexity of your code is O(n^2). See Complexity of erase here.
You have to do it in O(n).

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.