#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long LL;
const int MAXN = 1e4+5;
const LL INF = 1e15+5;
LL a[MAXN], sum[MAXN], ans[MAXN];
int main()
{
int n, m;
while(cin>>n>>m)
{
for(int i=1; i<=n; i++)
scanf("%lld",&a[i]);
sort(a+1, a+1+n);
sum[0] = ans[0] = 0;
for(int i=1; i<=n; i++)
{
sum[i] = sum[i-1] + a[i];
ans[i] = ans[i-1] + a[i]*a[i];
}
double Min = (double)INF;
for(int i=m; i<=n; i++)
{
double tmp = (ans[i]-ans[i-m])-1.0*(sum[i]-sum[i-m])*(sum[i]-sum[i-m])/m;
if(tmp < Min)
Min = tmp;
}
printf("%lld\n",(LL)Min);
}
return 0;
}

最新文章

  1. Python学习路程day20
  2. 爱上MVC~MVC4模型验证可以放在前端
  3. 应用 CSS3 动画实现12种风格的通知提示
  4. jquery对标签属性操作
  5. 本地连接虚拟机上面的redis
  6. PyCharm5.0.2最新版破解注册激活码
  7. yum命令详解
  8. Mysql中的存储过程
  9. HTML--2图片热点,网页划区,拼接
  10. 自己动手写ORM
  11. 重构2-Move Method(方法移动)
  12. android switch语句case expressions must be constant expressions
  13. sysbench使用教程【转载】
  14. 全文检索-Elasticsearch (四) elasticsearch.net 客户端
  15. 1.4部署到IIS「深入浅出ASP.NET Core系列」
  16. mysql执行sql语句过程
  17. 使用vue-cli开发过程中如何把jQuery设置为全局
  18. 解决Maven下载依赖慢的问题(转)
  19. Informatica_(2)第一个例子
  20. list集合与HashMap的使用

热门文章

  1. Cubieboard搭建Hadoop指南
  2. cf246 ENew Reform (并查集找环)
  3. wpf 导出Excel Wpf Button 样式 wpf简单进度条 List泛型集合对象排序 C#集合
  4. 【转载】How browsers work--Behind the scenes of modern web browsers (前端必读)
  5. angularjs学习之六(angularjs中directive指令的一般编程事件绑定 模板使用等)
  6. 第3周课后实践&amp;#183;程序阅读(4)-利用引用訪问私有数据成员
  7. 2016/2/25 1, margin auto 垂直方向测试 无效 2,margin重叠 3,哪些是块状哪些是内联 4,display:block inline 导航栏把内联转块状最常见+ 扩展
  8. JavaScript的高大强
  9. ubuntu字符界面下显示中文和调整分辨率
  10. 使用scanf_s报错:0xC0000005: Access violation writing location 0x00000000