#3627

Maximum Median Sum of Subsequences of Size 3

medium · 65.1% accepted · 79 likes · top 69%

array · math · greedy · sorting · game theory

Description

You are given an integer array nums with a length divisible by 3.

You want to make the array empty in steps. In each step, you can select any three elements from the array, compute their median, and remove the selected elements from the array.

The median of an odd-length sequence is defined as the middle element of the sequence when it is sorted in non-decreasing order.

Return the maximum possible sum of the medians computed from the selected elements.

Solution