結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
52,776 KB
testcase_01 AC 115 ms
54,068 KB
testcase_02 AC 115 ms
54,296 KB
testcase_03 AC 120 ms
54,012 KB
testcase_04 AC 117 ms
54,252 KB
testcase_05 AC 123 ms
54,264 KB
testcase_06 AC 120 ms
53,920 KB
testcase_07 AC 122 ms
53,984 KB
testcase_08 AC 120 ms
53,860 KB
testcase_09 AC 110 ms
53,124 KB
testcase_10 AC 119 ms
54,076 KB
testcase_11 AC 122 ms
54,352 KB
testcase_12 AC 127 ms
54,308 KB
testcase_13 AC 121 ms
53,724 KB
testcase_14 AC 122 ms
53,932 KB
testcase_15 AC 123 ms
54,040 KB
testcase_16 AC 120 ms
53,896 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 124 ms
54,332 KB
testcase_20 AC 152 ms
54,124 KB
testcase_21 AC 161 ms
54,528 KB
testcase_22 AC 163 ms
54,400 KB
testcase_23 AC 161 ms
54,132 KB
testcase_24 AC 128 ms
54,008 KB
testcase_25 AC 157 ms
54,056 KB
testcase_26 AC 163 ms
54,632 KB
testcase_27 AC 150 ms
54,300 KB
testcase_28 AC 147 ms
54,404 KB
testcase_29 AC 159 ms
54,668 KB
testcase_30 AC 148 ms
54,328 KB
testcase_31 AC 155 ms
54,288 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;

		
		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