이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// I was grinning like I'm winning, I was hitting my marks
// 'Cause I can do it with a broken heart 
// 1 2 3 4 ...
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <bitset>
typedef long long ll;
typedef long double ld;
using namespace std;
vector<ll> a, pf;
ld avg(int l, int r) { return (ld)(pf[r + 1] - pf[l]) / (ld)(r - l + 1); }
void chmax(ld& a, ld b) { a = max(a, b); }
void chmin(ld& a, ld b) { a = min(a, b); }
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	a.assign(n, 0), pf.assign(n + 1, 0);
	for (int i = 0; i < n; i++) cin >> a[i], pf[i + 1] = pf[i] + a[i];
	ld ans = a[n - 1];
	for (int l = 0; l < n; l++) for (int r = l; r < n; r++)
	{
		ld c = avg(l, r);
		ld mi = avg(0, n - 1);
		ld mx = avg(0, n - 1);
		if (c > mi || mi - c > ans) continue;
		int li = 0, ri = n - 1;
		while (li < ri)
		{
			if (avg(li, ri - 1) >= c) ri--;
			else li++;
			chmin(mi, avg(li, ri));
			chmax(mx, avg(li, ri));
			if (mx - mi > ans) break;
		}
		chmin(ans, mx - mi);
	}
	cout << setprecision(9) << fixed;
	cout << ans << "\n";
	return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |