比赛 |
20161114 |
评测结果 |
WAAWWAWWTT |
题目名称 |
社长的qwa |
最终得分 |
30 |
用户昵称 |
BIRD |
运行时间 |
2.614 s |
代码语言 |
C++ |
内存使用 |
0.28 MiB |
提交时间 |
2016-11-14 11:40:00 |
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
inline int read() {
int x, f = 1; char ch;
while(ch = getchar(), !isdigit(ch))
if(ch=='-')f=-1;x=ch-48;
while(ch = getchar(), isdigit(ch))
x = x*10 + ch - 48;
return x*f;
}
int enemy[10004];
int main()
{
int n, k, ans, fans;
freopen("qwa.in","r",stdin);
freopen("qwa.out","w",stdout);
n = read();k = read();
for(int i = 1; i <= k; i++)
enemy[i] = read();
sort(enemy,enemy+k+1);
for(int i = 1; i <= n-k+1; i++){
ans = 0;
for(int j = i;j <= i+k-1; j++)
for(int o = j+1; o <= i+k-1; o++)
ans+=abs(enemy[j]-enemy[o]);
fans = min(ans,fans);
}
printf("%d", fans);
return 0;
}