結果

問題 No.370 道路の掃除
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-16 17:41:49
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 785 bytes
コンパイル時間 1,796 ms
コンパイル使用メモリ 77,688 KB
実行使用メモリ 54,704 KB
最終ジャッジ日時 2024-05-04 14:22:02
合計ジャッジ時間 7,507 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
41,316 KB
testcase_01 AC 111 ms
41,212 KB
testcase_02 AC 115 ms
41,208 KB
testcase_03 AC 116 ms
41,448 KB
testcase_04 AC 115 ms
40,140 KB
testcase_05 AC 115 ms
41,704 KB
testcase_06 AC 97 ms
41,132 KB
testcase_07 AC 97 ms
40,216 KB
testcase_08 AC 110 ms
41,456 KB
testcase_09 AC 101 ms
41,568 KB
testcase_10 AC 126 ms
41,228 KB
testcase_11 AC 133 ms
41,612 KB
testcase_12 AC 122 ms
41,640 KB
testcase_13 AC 117 ms
41,776 KB
testcase_14 AC 118 ms
41,240 KB
testcase_15 AC 121 ms
41,284 KB
testcase_16 AC 127 ms
41,148 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 131 ms
41,740 KB
testcase_20 AC 164 ms
42,188 KB
testcase_21 AC 171 ms
42,164 KB
testcase_22 AC 161 ms
42,052 KB
testcase_23 AC 152 ms
42,224 KB
testcase_24 AC 125 ms
41,532 KB
testcase_25 AC 139 ms
41,780 KB
testcase_26 AC 154 ms
42,304 KB
testcase_27 AC 143 ms
41,804 KB
testcase_28 AC 137 ms
42,080 KB
testcase_29 AC 155 ms
42,180 KB
testcase_30 AC 166 ms
42,420 KB
testcase_31 AC 158 ms
42,004 KB
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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; 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