#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (l); --x)
typedef long long ll;
using namespace std;
const int N = 200'010;
double pos[N];
double sum;
int n;
vector<pair<double,double>> arr;
void make()
{
double sum = ::sum;
double m = sum/n;
int p0 = 0, p1 = n-1;
pos[n] = 2e9;
auto cur_pair = [&]() {
return pair<double,double>(sum/(p1-p0+1), (sum - pos[p0] + pos[p1+1])/(p1-p0+1));
};
arr = {cur_pair()};
for (int cnt = n; p0 < p1; --cnt) {
if ((sum-pos[p0])/(cnt-1) <= m) {
sum -= pos[p0];
++p0;
} else {
sum -= pos[p1];
--p1;
}
arr.push_back(cur_pair());
}
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
cin >> n;
Loop (i,0,n) {
ll x;
cin >> x;
pos[i] = x;
sum += pos[i];
}
make();
sort(arr.begin(), arr.end(), [](const pair<double,double> &a, const pair<double,double> &b){
return a.second < b.second;
});
LoopR (i,0,arr.size()-1)
arr[i].first = min(arr[i].first, arr[i+1].first);
double m = sum/n;
double ans = min(m - arr.front().first, arr.back().second - m);
Loop (i,0,arr.size()-1)
ans = min(ans, arr[i].second - arr[i+1].first);
cout << fixed << setprecision(9);
cout << ans << '\n';
}
Compilation message
seesaw.cpp: In function 'int main()':
seesaw.cpp:2:40: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<double, double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
2 | #define Loop(x,l,r) for (ll x = (l); x < (r); ++x)
| ^
seesaw.cpp:53:2: note: in expansion of macro 'Loop'
53 | Loop (i,0,arr.size()-1)
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
35 ms |
7936 KB |
Output is correct |
13 |
Correct |
34 ms |
8012 KB |
Output is correct |
14 |
Correct |
42 ms |
8004 KB |
Output is correct |
15 |
Correct |
35 ms |
7948 KB |
Output is correct |
16 |
Correct |
45 ms |
7940 KB |
Output is correct |