-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
2018201023_5.cpp
151 lines (132 loc) · 2.76 KB
/
2018201023_5.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <bits/stdc++.h>
#include<string.h>
#define INF 1000000000
using namespace std;
long long int max[1000000],min[1000000];
void convertMINH(long long int a[],long long int i, long long int n)
{
long long int l= 2*i+1;
long long int r= 2*i+2;
long long int small = i;
if (l<n && a[l]<a[small])
{
small= l;
}
if (r<n && a[r]< a[small])
{
small= r;
}
if (small!= i) {
swap(a[i],a[small]);
convertMINH(a, small, n);
}
}
void MinH(long long int a[] , long long int n)
{
long long int ht1 = (n - 1) / 2;
for (long long int i = ht1; i >= 0; i--)
{
convertMINH(a, i, n);
}
}
void convertMAXH(long long int a[], long long int i,long long int n)
{
long long int l= 2*i+1;
long long int r= 2*i+2;
long long int largest = i;
if (l<n && a[l]> a[largest])
{
largest = l;
}
if (r<n && a[r]>a[largest])
{
largest = r;
}
if (largest!=i) {
swap(a[i],a[largest]);
convertMAXH(a, largest, n);
}
}
void MaxH(long long int a[],long long int n)
{
long long int ht1 = (n - 1) / 2;
for (long long int i = ht1; i >= 0; i--)
{
convertMAXH(a, i, n);
}
}
int main()
{
long long int n;
cin>>n;
long long int a[n],max[n],min[n];
long long int x1=0,x2=0;
double mid=0;
cout<<setprecision(1)<<fixed;
for(long long int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]<mid)
{
//int q=x1-1;
// cout<<q<<" ";
max[x1++]=a[i];
// x1++;
if(max[x1-1]>max[0])
swap(max[x1-1],max[0]);
}
else
{
//int p=x2-1;
// cout<<p<<" ";
min[x2++]=a[i];
// x2++;
if(min[x2-1]<min[0])
swap(min[x2-1],min[0]);
}
//for(long long int i=0;i<n;i++)
//cout<<a[i]<<" ";
if((x1-x2)>1||(x2-x1)>1)
{
long long int p,q,r,s;
if(x1>x2)
{
swap(max[x1-1],max[0]);
q=--x1;
p=x2++;
min[p]=max[q];
swap(min[0],min[x2-1]);
MaxH(max,x1);
}
else
{
swap(min[x2-1],min[0]);
s=--x2;
r=x1++;
max[r]=min[s];
swap(max[0],max[x1-1]);
MinH(min,x2);
}
//for(long long int i=0;i<n;i++)
//cout<<a[i]<<" ";
}
//cout<<mid<<" ";
if(x1==x2)
{
mid=double((max[0]+min[0]))/2;
}
//cout<<mid<<" ";
else if(x1>x2)
{
mid=double(max[0]);
//cout<<mid<<" ";
}
else
{
mid=double(min[0]);
}
//cout<<mid<<endl;
cout<<mid<<endl;
}
return 0;
}