-
Notifications
You must be signed in to change notification settings - Fork 0
/
2108.cpp
56 lines (49 loc) · 1.16 KB
/
2108.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 2022.02.25 23:29:11
// 2108 https://boj.kr/2108
#include <bits/stdc++.h>
using namespace std;
int numbers[500001];
int freq[10000];
int n;
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> n;
int total = 0;
for (int i = 0; i < n; i++)
{
int num;
cin >> num;
numbers[i] = num;
total += num;
freq[num + 4000]++;
}
sort(numbers, numbers + n);
int mostFreq = 0;
int prevMostFreq = 0;
for (int i = n-1; i >=0; i--)
{
int num = numbers[i];
int frequency = freq[num + 4000];
int prevFrequency = freq[mostFreq + 4000];
i -= frequency - 1;
if (frequency == prevFrequency)
{
prevMostFreq = mostFreq;
mostFreq = num;
}
if (frequency > prevFrequency)
{
prevMostFreq = 0;
mostFreq = num;
}
}
cout << (int)round((double)total / n) << '\n';
cout << numbers[n / 2] << '\n';
if (freq[mostFreq+4000]== freq[prevMostFreq+4000])
cout << prevMostFreq << '\n';
else
cout << mostFreq << '\n';
cout << (numbers[n - 1] - numbers[0]);
}