#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<iomanip>
using namespace std;
long long int n, k;
long long int sum;
int main(){
while (cin >> n >> k){
long long int m;
sum = 0;
vector<long long int> arr;
for (int i = 0; i < n; i++){
cin >> m;
arr.push_back(m);
}
vector<long long int> amount(n);
int index1 = k - 1;
int index2 = n - k;
if (index1 <= index2){
int start = 0;
int t = 1;
while (start < index1){
amount[start] = t;
t++;
start++;
}
int end = n - 1;
t = 1;
while (end > index2){
amount[end] = t;
t++;
end--;
}
while (index1 <= index2){
amount[index1] = k;
index1++;
}
}
else{
int start = 0;
int t = 1;
while (start < index2){
amount[start] = t;
t++;
start++;
}
t = 1;
int end = n - 1;
while (end>index1){
amount[end] = t;
t++;
end--;
}
while (index2 <= index1){
amount[index2] = t;
index2++;
}
}
for (int i = 0; i < arr.size(); i++){
sum += (amount[i] * arr[i]);
}
double t = n - k + 1;
cout << fixed << setprecision(6) << sum / t << endl;
}
return 0;
}
Codeforces 808B Average Sleep Time
最新推荐文章于 2018-08-16 11:07:18 发布