結果

問題 No.370 道路の掃除
ユーザー ym678
提出日時 2016-09-28 20:17:41
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 531 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 75,580 KB
実行使用メモリ 55,016 KB
最終ジャッジ日時 2024-11-21 08:25:38
合計ジャッジ時間 8,785 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30 WA * 4
権限があれば一括ダウンロードができます

ソースコード

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