ARC 101 C - Candles

题面在这里!

 

    显然直接枚举左端点(右端点)就OK啦。

 

#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int N=1e5+5;
 
int n,a[N],ans=1e9,k;
 
inline int Get(int x,int y){
	if(x>=0) return y;
	if(y<=0) return -x;
	return y-x+min(y,-x);
}
 
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",a+i);
    
    sort(a+1,a+n+1);
    
    for(int i=k;i<=n;i++) ans=min(ans,Get(a[i-k+1],a[i]));
    
    printf("%d\n",ans);
    return 0;
}

  

posted @ 2018-08-26 11:23  蒟蒻JHY  阅读(204)  评论(0编辑  收藏  举报