41 lines
1.2 KiB
Java
41 lines
1.2 KiB
Java
import java.util.*;
|
|
|
|
public class _2108{
|
|
public static void main(String[] args){
|
|
Scanner sc = new Scanner(System.in);
|
|
int N = sc.nextInt();
|
|
int[] arr = new int[N];
|
|
int sum=0;
|
|
for(int i=0; i<N; i++){
|
|
arr[i] = sc.nextInt();
|
|
sum += arr[i];
|
|
}
|
|
Arrays.sort(arr);
|
|
int average = (int)Math.round((double)sum/N);
|
|
|
|
Map<Integer, Integer> map = new HashMap<>();
|
|
int maxFreqCount = 0;
|
|
int maxFreqVal=0;
|
|
for(int num : arr){
|
|
int count = map.getOrDefault(num, 0) + 1;
|
|
if(count>maxFreqCount){
|
|
maxFreqCount = count;
|
|
maxFreqVal = num;
|
|
}
|
|
map.put(num, count);
|
|
}
|
|
|
|
List<Integer> maxFreq = new ArrayList<>();
|
|
for(Map.Entry<Integer, Integer> entry : map.entrySet()){
|
|
if(entry.getValue() == maxFreqCount) maxFreq.add(entry.getKey());
|
|
}
|
|
|
|
if(maxFreq.size()>1) {
|
|
maxFreq.sort((a,b)->a-b);
|
|
maxFreqVal = maxFreq.get(1);
|
|
}
|
|
|
|
System.out.printf("%d\n%d\n%d\n%d\n",average, arr[N/2], maxFreqVal, arr[N-1]-arr[0]);
|
|
sc.close();
|
|
}
|
|
} |