結果

問題 No.370 道路の掃除
ユーザー 37zigen
提出日時 2016-05-13 23:43:14
言語 Java
(openjdk 23)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 675 bytes
コンパイル時間 2,156 ms
コンパイル使用メモリ 74,028 KB
実行使用メモリ 42,168 KB
最終ジャッジ日時 2024-10-14 16:47:49
合計ジャッジ時間 7,558 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Arrays;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int[] d=new int[m];
		int min_d=999999999;
		for(int i=0;i<m;i++){
			d[i]=sc.nextInt();
		}
		Arrays.sort(d);
		for(int i=0;i+n<=m;i++){
			min_d=Math.min(min_d, calc(d[i],d[i+n-1]));
		}
		System.out.println(min_d);
	}
	int calc(int left,int right){
		if(left<=0&&right<=0)return -left;
		if(left<0&&right>0)return Math.min(-2*left+right,-left+2*right);
		if(left>=0&&right>0)return right;
		else return -1;//error
	}
}
0