-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboj2108.cpp
65 lines (60 loc) · 1.37 KB
/
boj2108.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
57
58
59
60
61
62
63
64
65
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
using namespace std;
using p = pair<int, int>;
using ll = long long;
const int MAX = 10e+6;
const int INF = 0x66554433;
inline void Quick_IO(){
ios_base :: sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
vector<int> median;
int main(){
Quick_IO();
int N;
cin>>N;
ll sum = 0;
int minValue = INF;
int maxValue = -INF;
map<int, int> arr;
for (int i = 0; i < N; ++i) {
int a;
cin>>a;
sum+=a;
median.push_back(a);
minValue = min(minValue, a);
maxValue = max(maxValue, a);
arr[a]++;
}
sort(median.begin(), median.end());
if(abs(sum%N)>N/2){
if(sum>0) cout<<sum/N+1<<endl;
else cout<<sum/N-1<<endl;
}else{
cout<<sum/N<<endl;
}
cout<<median[N/2]<<endl;
vector<p> counts(arr.begin(), arr.end());
sort(counts.begin(), counts.end(), [](p a, p b){
if(a.second==b.second){
return a.first<b.first;
}
return a.second>b.second;
});
if(counts.size()>1){
if(counts[0].second!=counts[1].second){
cout<<counts[0].first<<endl;
}else{
cout<<counts[1].first<<endl;
}
}else{
cout<<counts[0].first<<endl;
}
cout<<maxValue-minValue<<endl;
return 0;
}