比赛 20161114 评测结果 WAAWWAWWTT
题目名称 社长的qwa 最终得分 30
用户昵称 coolkid 运行时间 2.372 s
代码语言 C++ 内存使用 0.63 MiB
提交时间 2016-11-14 11:42:20
显示代码纯文本
  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. using namespace std;
  6.  
  7. const int MAXN=1e5;
  8.  
  9. int A[MAXN];
  10. int n,k;
  11.  
  12. void init(){
  13. scanf("%d%d",&n,&k);
  14. for(int i=1;i<=n;i++) scanf("%d",&A[i]);
  15. }
  16.  
  17. typedef long long LL;
  18. LL ans=(LL)2147483647*100000LL;
  19.  
  20. LL min(LL a,LL b){
  21. if(a>b) return b;
  22. return a;
  23. }
  24.  
  25. LL update(int st,int en){
  26. LL res=0;
  27. for(int i=st;i<=en;i++)
  28. for(int j=i+1;j<=en;j++) res+=abs(A[i]-A[j]);
  29. return res;
  30. }
  31.  
  32. void work(){
  33. ans=update(1,k);
  34. for(int i=k+1;i<=n;i++)//End
  35. ans=min(ans,update(i-k+1,i));
  36. cout<<ans<<endl;
  37. }
  38.  
  39. int main(){
  40. freopen("qwa.in","r",stdin);
  41. freopen("qwa.out","w",stdout);
  42. init();
  43. work();
  44. return 0;
  45. }