 # MEENA_003 Editorial

Practice

Author: Yogesh Deolalkar
Tester: Ram Agrawal
Editorialist: Prathamesh Sogale

SIMPLE.

Math , Array

# PROBLEM:

Meena has given you an array of size n. He allowed you to modify the array in the following way, in one operation you can swap any two elements of the array. Formally, a swap means you can choose two indices i,j 1≤i,j≤n (indexing starts from 1) and exchange the values of ai and aj

He is greedy and likes smaller numbers, so he wants you to minimize the Exclusive Mean of the array. The exclusive mean of an array is defined as follows:

Given an array, at each step, you choose the two left-most elements and replace them with their average (arithmetic mean).

Formally, you choose a1 and a2, delete them from the array, and add (a1+a2)/2 at the beginning of the array.

Note that the value shouldn’t be rounded off to an integer and also the size of the array decreases by 1 after each operation.

You repeat the process n−1 times until you are left with only one element. This value is called as Exclusive Mean

You can make any number of operations you want so that the Exclusive Mean of the array is minimized.

You are required to print the array configuration that has the least value of Exclusive Mean.

Note: you don’t need to minimize the number of operations or print the minimum possible value of Exclusive Mean.

# QUICK EXPLANATION:

Sort the given array and print it in reverse order.

# SOLUTIONS:

Setter's Solution

T=int(input())
for _ in range(T):
n=int(input())
a=list(map(int,input().split()))
a.sort(reverse=True)
print(*a)

Tester's Solution

#include <bits/stdc++.h>
using namespace std;

int main() {
int t;
cin>>t;
while(t–){
int n;
cin>>n;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
sort(arr,arr+n);
for(int i=n-1;i>=0;i–){
cout<<arr[i]<<" ";
}
cout<<endl;
}
return 0;
}