https://atcoder.jp/contests/abc236/tasks/abc236_e
#include<iostream>
#include<cmath>
using namespace std;

const int N = 1e3 + 10;
int a[N], b[N];
int n;

template <class T> bool check(T tar, T b[]) {
T f = 0, g = 0;
for (int i =1; i<= n; i++) {
T t = max (f, g) + b[i];
g = f;
f = t;
}
return max (f, g) >= 0;
}
int main () {
cin >> n;
for (int i =1; i<= n; i ++) cin >> a[i];
double l = 1.0, r = 1e9 * 1.0;
while ((r - l) / l > 1e-7) {
double mid = sqrt(r * l);
double b[N];
for (int i = 1; i <= n ;i ++)
b[i] = a[i] - mid;
if (check(mid, b)) r = mid;
else l = mid;
}
cout << l << endl;
int l1 = 0, r1 = 1e9;
while (l < r ) {
int mid = l1 + r1>> 1;
int b[N];
for (int i = 1; i <= n; i++)
if (a[i] >= mid) b[i] = 1;
else b[i] = -1;
if (check(mid, b)) r1 = mid;
else l1 = mid + 1;
}
cout << l1 << endl;
return 0;
}

如果一个平均数存在当且仅当每个数减去这个数,后存在一最大的sum大于=0 如果一个中位数存在当且仅当构造一个新的数组,后存在一个最大的sum > 0