結果

問題 No.370 道路の掃除
ユーザー ym678ym678
提出日時 2016-09-28 20:33:28
言語 Java21
(openjdk 21)
結果
AC  
実行時間 171 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 2,006 ms
コンパイル使用メモリ 74,880 KB
実行使用メモリ 54,552 KB
最終ジャッジ日時 2024-05-01 06:27:01
合計ジャッジ時間 7,523 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
53,756 KB
testcase_01 AC 116 ms
54,152 KB
testcase_02 AC 110 ms
52,948 KB
testcase_03 AC 114 ms
53,696 KB
testcase_04 AC 103 ms
52,820 KB
testcase_05 AC 103 ms
52,988 KB
testcase_06 AC 103 ms
52,808 KB
testcase_07 AC 114 ms
54,284 KB
testcase_08 AC 117 ms
54,020 KB
testcase_09 AC 104 ms
52,820 KB
testcase_10 AC 121 ms
54,168 KB
testcase_11 AC 132 ms
54,080 KB
testcase_12 AC 136 ms
53,872 KB
testcase_13 AC 125 ms
54,144 KB
testcase_14 AC 123 ms
54,352 KB
testcase_15 AC 124 ms
54,040 KB
testcase_16 AC 125 ms
54,220 KB
testcase_17 AC 122 ms
53,896 KB
testcase_18 AC 122 ms
54,256 KB
testcase_19 AC 122 ms
53,888 KB
testcase_20 AC 170 ms
54,468 KB
testcase_21 AC 156 ms
54,384 KB
testcase_22 AC 161 ms
54,320 KB
testcase_23 AC 155 ms
54,280 KB
testcase_24 AC 132 ms
54,112 KB
testcase_25 AC 160 ms
54,104 KB
testcase_26 AC 166 ms
54,168 KB
testcase_27 AC 147 ms
54,464 KB
testcase_28 AC 151 ms
54,240 KB
testcase_29 AC 157 ms
54,068 KB
testcase_30 AC 171 ms
54,552 KB
testcase_31 AC 150 ms
54,244 KB
testcase_32 AC 153 ms
54,056 KB
testcase_33 AC 165 ms
54,348 KB
権限があれば一括ダウンロードができます

ソースコード

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