Codeforces 808B Average Sleep Time

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值