結果

問題 No.370 道路の掃除
ユーザー ym678ym678
提出日時 2016-09-28 20:17:41
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 531 bytes
コンパイル時間 2,312 ms
コンパイル使用メモリ 76,260 KB
実行使用メモリ 54,876 KB
最終ジャッジ日時 2024-05-01 06:25:12
合計ジャッジ時間 7,509 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
52,652 KB
testcase_01 AC 100 ms
52,892 KB
testcase_02 AC 112 ms
53,984 KB
testcase_03 AC 113 ms
54,404 KB
testcase_04 AC 116 ms
54,312 KB
testcase_05 AC 118 ms
53,892 KB
testcase_06 AC 104 ms
52,648 KB
testcase_07 AC 113 ms
53,516 KB
testcase_08 AC 104 ms
52,792 KB
testcase_09 AC 110 ms
54,128 KB
testcase_10 AC 126 ms
53,984 KB
testcase_11 AC 126 ms
53,792 KB
testcase_12 AC 127 ms
54,300 KB
testcase_13 AC 121 ms
53,692 KB
testcase_14 AC 126 ms
54,036 KB
testcase_15 AC 118 ms
53,804 KB
testcase_16 AC 118 ms
54,300 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 126 ms
54,164 KB
testcase_20 AC 160 ms
54,640 KB
testcase_21 AC 154 ms
54,456 KB
testcase_22 AC 153 ms
54,396 KB
testcase_23 AC 154 ms
54,128 KB
testcase_24 AC 125 ms
53,888 KB
testcase_25 AC 140 ms
54,224 KB
testcase_26 AC 169 ms
54,268 KB
testcase_27 AC 132 ms
54,176 KB
testcase_28 AC 147 ms
54,280 KB
testcase_29 AC 153 ms
54,228 KB
testcase_30 AC 172 ms
54,568 KB
testcase_31 AC 161 ms
54,548 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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