-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
45 lines (44 loc) · 897 Bytes
/
C.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
#include "bits/stdc++.h"
using namespace std;
double a[1000010];
struct data {
double first, avg;
int second;
data (double first, int second, double avg) : first(first), second(second), avg(avg) {}
data () {}
};
int main(int argc, char const *argv[])
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
a[i] = x;
}
vector <data> v;
for(int i = n; i >= 1; i--) {
double opt = a[i];
double sum = a[i];
int id = i;
while(!v.empty()) {
sum += v.back().first;
if(opt >= (sum / (v.back().second - i + 1))) {
opt = (sum / (v.back().second - i + 1));
id = v.back().second;
v.pop_back();
} else {
sum -= v.back().first;
break;
}
}
v.push_back(data(sum, id, opt));
}
for(int i = 1; i <= n; i++) {
while(!v.empty() && v.back().second < i) {
v.pop_back();
}
printf("%.10lf\n", v.back().avg);
}
return 0;
}