-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuva-10057.cpp
More file actions
85 lines (64 loc) · 1.64 KB
/
uva-10057.cpp
File metadata and controls
85 lines (64 loc) · 1.64 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
using namespace std;
/* something starts */
/* something ends */
/* typedef starts */
typedef long long ll;
typedef unsigned long long ull;
/* typedef ends */
/* macro starts */
#define PI acos(-1.0)
#define MAX 65540
/* macro ends */
int frequency[MAX];
vector<int>data;
void initialize()
{
data.clear();
for (int i = 0; i < MAX; i++) {
frequency[i] = 0;
}
}
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, i, x, median, low, high, lowV, highV, diff, _count;
while (scanf("%d", &n) != EOF) {
initialize();
for (i = 1; i <= n; i++) {
scanf("%d", &x);
data.push_back(x);
frequency[x]++;
}
sort(data.begin(), data.end());
/// n is odd
if (n & 1) {
median = data[n / 2];
_count = frequency[median];
diff = 1;
}
/// n is even
else {
high = n / 2;
low = high - 1;
highV = data[high];
lowV = data[low];
if (lowV == highV) {
median = lowV;
_count = frequency[lowV];
diff = 1;
}
else {
median = min(lowV, highV);
_count = frequency[lowV] + frequency[highV];
diff = highV - lowV + 1;
}
}
printf("%d %d %d\n", median, _count, diff);
}
return 0;
}