結果

問題 No.370 道路の掃除
ユーザー ym678
提出日時 2016-09-28 20:33:28
言語 Java
(openjdk 23)
結果
AC  
実行時間 193 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 3,431 ms
コンパイル使用メモリ 74,940 KB
実行使用メモリ 54,564 KB
最終ジャッジ日時 2024-11-21 08:33:06
合計ジャッジ時間 10,106 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int N = scn.nextInt();
		int M = scn.nextInt();
		int dp[] = new int[M];
		int ans = Integer.MAX_VALUE/2;

		
		for(int i=0; i<M; i++){
			dp[i] = scn.nextInt();
		}
		Arrays.sort(dp);		
		for(int i=0; i<=M-N; i++){	
			 ans = Math.min(ans , Math.abs(dp[i] - dp[i+N-1]) +
					              Math.min(Math.abs(dp[i]), Math.abs(dp[i+N-1])));
		}
		System.out.println(ans);
	}
}
0