結果

問題 No.370 道路の掃除
ユーザー tentententen
提出日時 2020-10-15 08:42:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 172 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 3,433 ms
コンパイル使用メモリ 71,544 KB
実行使用メモリ 58,272 KB
最終ジャッジ日時 2023-09-28 01:06:05
合計ジャッジ時間 7,767 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 109 ms
55,748 KB
testcase_01 AC 109 ms
55,496 KB
testcase_02 AC 110 ms
55,948 KB
testcase_03 AC 109 ms
55,816 KB
testcase_04 AC 109 ms
55,672 KB
testcase_05 AC 110 ms
55,664 KB
testcase_06 AC 110 ms
56,180 KB
testcase_07 AC 109 ms
55,692 KB
testcase_08 AC 112 ms
55,748 KB
testcase_09 AC 109 ms
55,828 KB
testcase_10 AC 118 ms
58,272 KB
testcase_11 AC 120 ms
55,636 KB
testcase_12 AC 117 ms
55,820 KB
testcase_13 AC 116 ms
55,864 KB
testcase_14 AC 114 ms
55,924 KB
testcase_15 AC 115 ms
55,740 KB
testcase_16 AC 118 ms
55,684 KB
testcase_17 AC 117 ms
55,424 KB
testcase_18 AC 121 ms
56,236 KB
testcase_19 AC 117 ms
55,660 KB
testcase_20 AC 159 ms
56,340 KB
testcase_21 AC 159 ms
56,188 KB
testcase_22 AC 157 ms
58,068 KB
testcase_23 AC 166 ms
55,904 KB
testcase_24 AC 123 ms
56,008 KB
testcase_25 AC 156 ms
56,208 KB
testcase_26 AC 172 ms
56,572 KB
testcase_27 AC 146 ms
55,660 KB
testcase_28 AC 160 ms
56,184 KB
testcase_29 AC 168 ms
55,828 KB
testcase_30 AC 168 ms
56,412 KB
testcase_31 AC 163 ms
55,656 KB
testcase_32 AC 159 ms
55,912 KB
testcase_33 AC 155 ms
55,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int m = sc.nextInt();
    	int[] points = new int[m];
    	for (int i = 0; i < m; i++) {
    	    points[i] = sc.nextInt();
    	}
    	Arrays.sort(points);
    	int min = Integer.MAX_VALUE;
    	for (int i = 0; i + n <= m; i++) {
    	    int end = i + n - 1;
    	    if (points[i] * points[end] < 0) {
    	        min = Math.min(min, points[end] - points[i] + Math.min(-points[i], points[end]));
    	    } else {
    	        if (points[i] < 0) {
    	            min = Math.min(min, -points[i]);
    	        } else {
    	            min = Math.min(min, points[end]);
    	        }
    	    }
    	}
    	System.out.println(min);
	}
}
0