結果

問題 No.370 道路の掃除
ユーザー ぴろずぴろず
提出日時 2016-07-18 22:04:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 1,868 ms
コンパイル使用メモリ 74,120 KB
実行使用メモリ 42,712 KB
最終ジャッジ日時 2024-04-23 16:36:00
合計ジャッジ時間 7,562 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
41,496 KB
testcase_01 AC 114 ms
41,368 KB
testcase_02 AC 106 ms
40,432 KB
testcase_03 AC 114 ms
41,140 KB
testcase_04 AC 104 ms
40,052 KB
testcase_05 AC 114 ms
41,284 KB
testcase_06 AC 115 ms
41,296 KB
testcase_07 AC 112 ms
41,024 KB
testcase_08 AC 113 ms
41,144 KB
testcase_09 AC 116 ms
41,592 KB
testcase_10 AC 128 ms
41,388 KB
testcase_11 AC 124 ms
42,100 KB
testcase_12 AC 124 ms
41,336 KB
testcase_13 AC 121 ms
41,192 KB
testcase_14 AC 123 ms
41,672 KB
testcase_15 AC 126 ms
41,932 KB
testcase_16 AC 124 ms
41,172 KB
testcase_17 AC 129 ms
41,512 KB
testcase_18 AC 124 ms
41,160 KB
testcase_19 AC 126 ms
41,724 KB
testcase_20 AC 165 ms
42,712 KB
testcase_21 AC 158 ms
42,192 KB
testcase_22 AC 156 ms
42,200 KB
testcase_23 AC 160 ms
42,640 KB
testcase_24 AC 138 ms
41,484 KB
testcase_25 AC 152 ms
41,044 KB
testcase_26 AC 168 ms
42,652 KB
testcase_27 AC 144 ms
41,748 KB
testcase_28 AC 155 ms
41,488 KB
testcase_29 AC 162 ms
42,404 KB
testcase_30 AC 172 ms
42,168 KB
testcase_31 AC 157 ms
41,916 KB
testcase_32 AC 159 ms
42,380 KB
testcase_33 AC 163 ms
42,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no370;

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i=0;i<n;i++) {
			d[i] = sc.nextInt();
		}
		Arrays.sort(d);
		int ans = Integer.MAX_VALUE;
		for(int i=0;i<=n-k;i++) {
			int left = d[i];
			int right = d[i+k-1];
			ans = Math.min(ans, Math.min(Math.abs(left), Math.abs(right)) + Math.abs(left - right));
		}
		System.out.println(ans);
	}

}
0