結果

問題 No.370 道路の掃除
ユーザー ym678ym678
提出日時 2016-09-28 20:33:28
言語 Java19
(openjdk 21)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 532 bytes
コンパイル時間 2,235 ms
コンパイル使用メモリ 77,032 KB
実行使用メモリ 57,624 KB
最終ジャッジ日時 2023-08-13 13:14:25
合計ジャッジ時間 9,241 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
56,100 KB
testcase_01 AC 127 ms
55,828 KB
testcase_02 AC 128 ms
55,904 KB
testcase_03 AC 129 ms
55,544 KB
testcase_04 AC 129 ms
55,696 KB
testcase_05 AC 124 ms
56,136 KB
testcase_06 AC 126 ms
56,184 KB
testcase_07 AC 125 ms
55,848 KB
testcase_08 AC 129 ms
55,776 KB
testcase_09 AC 131 ms
56,072 KB
testcase_10 AC 138 ms
55,904 KB
testcase_11 AC 144 ms
55,740 KB
testcase_12 AC 141 ms
55,848 KB
testcase_13 AC 139 ms
55,672 KB
testcase_14 AC 141 ms
56,112 KB
testcase_15 AC 137 ms
55,916 KB
testcase_16 AC 135 ms
55,864 KB
testcase_17 AC 139 ms
55,844 KB
testcase_18 AC 141 ms
57,624 KB
testcase_19 AC 138 ms
55,760 KB
testcase_20 AC 186 ms
55,856 KB
testcase_21 AC 184 ms
56,140 KB
testcase_22 AC 172 ms
56,508 KB
testcase_23 AC 181 ms
55,056 KB
testcase_24 AC 142 ms
55,904 KB
testcase_25 AC 177 ms
56,168 KB
testcase_26 AC 183 ms
56,768 KB
testcase_27 AC 160 ms
56,372 KB
testcase_28 AC 180 ms
55,976 KB
testcase_29 AC 178 ms
56,396 KB
testcase_30 AC 189 ms
56,432 KB
testcase_31 AC 178 ms
55,972 KB
testcase_32 AC 182 ms
56,360 KB
testcase_33 AC 190 ms
56,300 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