You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Distribute a vector of integers into n vectors. No vector is empty. What is the maximum possible sum of median for all the vectors?
The median of an array is the middle element if the array is sorted in non-decreasing order. If the size of the array is even, the median is the average of the two middle elements. Round up to the next integer.
1 <= n <= len(v)
*/
classSolution {
public:
longMaxSum(vector<int> v, int n){
int sz = v.size();
sort(v.begin(), v.end());
// distribute the max n-1 elements into n-1 vectors, and the rest into a single vector
sz -= n-1;
long res = accumulate(v.begin() + sz, v.end(), 0);