CF#808 B. Average Sleep Time(水题)

来源:互联网 发布:金字塔软件使用说明书 编辑:程序博客网 时间:2024/06/05 14:27
B. Average Sleep Time
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

It's been almost a week since Polycarp couldn't get rid of insomnia. And as you may already know, one week in Berland lasts k days!

When Polycarp went to a doctor with his problem, the doctor asked him about his sleeping schedule (more specifically, the average amount of hours of sleep per week). Luckily, Polycarp kept records of sleep times for the last n days. So now he has a sequencea1, a2, ..., an, where ai is the sleep time on the i-th day.

The number of records is so large that Polycarp is unable to calculate the average value by himself. Thus he is asking you to help him with the calculations. To get the average Polycarp is going to consider k consecutive days as a week. So there will be n - k + 1 weeks to take into consideration. For example, if k = 2n = 3 and a = [3, 4, 7], then the result is .

You should write a program which will calculate average sleep times of Polycarp over all weeks.

Input

The first line contains two integer numbers n and k (1 ≤ k ≤ n ≤ 2·105).

The second line contains n integer numbers a1, a2, ..., an (1 ≤ ai ≤ 105).

Output

Output average sleeping time over all weeks.

The answer is considered to be correct if its absolute or relative error does not exceed 10 - 6. In particular, it is enough to output real number with at least 6 digits after the decimal point.

Examples
input
3 23 4 7
output
9.0000000000
input
1 110
output
10.0000000000
input
8 21 2 4 100000 123 456 789 1
output
28964.2857142857
Note

In the third example there are n - k + 1 = 7 weeks, so the answer is sums of all weeks divided by 7.

#include<bits/stdc++.h>using namespace std;const int N = 2e5 + 10;int n, k;double a[N];int main(){    while(scanf("%d%d", &n, &k) == 2){        a[0] = 0;        scanf("%lf", &a[1]);        for(int i = 2; i <= n; i++){            scanf("%lf", &a[i]);            a[i] += a[i-1];        }        double ans = 0;        for(int i = 0; i <= n-k; i++){            ans += a[i+k]-a[i];        }        printf("%.10f\n", ans/(n-k+1));    }}



原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 硬件系统不兼容怎么办 系统主板不兼容怎么办 安装软件不兼容怎么办 win10驱动不尖锐怎么办 苹果内存太小怎么办 内存太小怎么办手机 苹果手机屏幕不能滑动怎么办 vivo手机软件不兼容怎么办 微信无法录音怎么办 手机卡住了怎么办vivo 好钱包闪退怎么办 闲鱼认证失败怎么办 闲鱼买了假门票怎么办 买黄金买到假的怎么办 闲鱼被买家骗了怎么办 闲鱼上小视频没法保存怎么办 qq空间无法查看怎么办 华为手机电池不耐用怎么办 内内被动过怎么办 hp电脑开机黑屏怎么办 网上开店快递费怎么办 保温杯外壳掉漆怎么办 拖鞋前面磨脚怎么办 塑料拖鞋磨脚怎么办 路由器进不去设置界面怎么办 手机号丢了微信登不上怎么办 电脑总是闪黑屏怎么办 支付宝破产钱怎么办 淘宝号码注册过怎么办 农行k宝怎么办信用卡 电脑页面无法显示怎么办 对方银行停止收款怎么办 淘宝东西买太多怎么办 淘宝号黑号了怎么办… 中通包裹异常怎么办 包裹退回去了怎么办 qq支付密码错误怎么办 ie8出现闪退怎么办 平板输不了密码怎么办 华硕笔记本键盘打不开怎么办 电脑打不开rar文件怎么办