比赛 |
20161114 |
评测结果 |
WAAWWAWWTT |
题目名称 |
社长的qwa |
最终得分 |
30 |
用户昵称 |
coolkid |
运行时间 |
2.372 s |
代码语言 |
C++ |
内存使用 |
0.63 MiB |
提交时间 |
2016-11-14 11:42:20 |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<algorithm>
- using namespace std;
-
- const int MAXN=1e5;
-
- int A[MAXN];
- int n,k;
-
- void init(){
- scanf("%d%d",&n,&k);
- for(int i=1;i<=n;i++) scanf("%d",&A[i]);
- }
-
- typedef long long LL;
- LL ans=(LL)2147483647*100000LL;
-
- LL min(LL a,LL b){
- if(a>b) return b;
- return a;
- }
-
- LL update(int st,int en){
- LL res=0;
- for(int i=st;i<=en;i++)
- for(int j=i+1;j<=en;j++) res+=abs(A[i]-A[j]);
- return res;
- }
-
- void work(){
- ans=update(1,k);
- for(int i=k+1;i<=n;i++)//End
- ans=min(ans,update(i-k+1,i));
- cout<<ans<<endl;
- }
-
- int main(){
- freopen("qwa.in","r",stdin);
- freopen("qwa.out","w",stdout);
- init();
- work();
- return 0;
- }