結果

問題 No.370 道路の掃除
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-16 17:56:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 2,032 ms
コンパイル使用メモリ 74,232 KB
実行使用メモリ 56,464 KB
最終ジャッジ日時 2023-08-17 07:29:34
合計ジャッジ時間 8,548 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
55,984 KB
testcase_01 AC 126 ms
55,604 KB
testcase_02 AC 126 ms
56,156 KB
testcase_03 AC 122 ms
56,008 KB
testcase_04 AC 125 ms
56,044 KB
testcase_05 AC 124 ms
55,912 KB
testcase_06 AC 124 ms
56,456 KB
testcase_07 AC 124 ms
56,060 KB
testcase_08 AC 123 ms
55,792 KB
testcase_09 AC 123 ms
55,788 KB
testcase_10 AC 133 ms
55,852 KB
testcase_11 AC 133 ms
55,976 KB
testcase_12 AC 132 ms
56,112 KB
testcase_13 AC 134 ms
56,160 KB
testcase_14 AC 134 ms
56,028 KB
testcase_15 AC 133 ms
54,164 KB
testcase_16 AC 131 ms
55,840 KB
testcase_17 AC 133 ms
55,804 KB
testcase_18 AC 134 ms
56,244 KB
testcase_19 AC 135 ms
56,464 KB
testcase_20 AC 184 ms
56,176 KB
testcase_21 AC 169 ms
56,120 KB
testcase_22 AC 177 ms
55,812 KB
testcase_23 AC 167 ms
56,124 KB
testcase_24 AC 139 ms
56,388 KB
testcase_25 AC 155 ms
56,044 KB
testcase_26 AC 184 ms
56,128 KB
testcase_27 AC 148 ms
55,996 KB
testcase_28 AC 173 ms
56,164 KB
testcase_29 AC 179 ms
56,252 KB
testcase_30 AC 185 ms
56,312 KB
testcase_31 AC 166 ms
56,420 KB
testcase_32 AC 180 ms
55,952 KB
testcase_33 AC 187 ms
56,272 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 [] D = new int [M];
        for(int i=0; i<M; i++){
            D[i]=sc.nextInt();
        }
        Arrays.sort(D);
        int min=Integer.MAX_VALUE;
        int d = 0;
        for(int i=0; i<M-N+1; i++){
            if(D[i]<0 && D[i+N-1]<0 ){
                d=Math.abs(D[i]);
            }else if(D[i]>0 && D[i+N-1]>0 ){
                d=D[i+N-1];
            }else{
                int a = 2*D[i+N-1]-D[i];
                int b = D[i+N-1]-2*D[i];
                d=Math.min(a,b);
            }
            min=Math.min(min,d);
        }
        System.out.println(min);
    }
}
0