結果

問題 No.370 道路の掃除
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-16 17:41:49
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 785 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 74,124 KB
実行使用メモリ 57,000 KB
最終ジャッジ日時 2023-08-17 07:29:25
合計ジャッジ時間 7,961 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
56,092 KB
testcase_01 AC 113 ms
56,424 KB
testcase_02 AC 114 ms
55,596 KB
testcase_03 AC 109 ms
55,900 KB
testcase_04 AC 114 ms
56,380 KB
testcase_05 AC 113 ms
55,580 KB
testcase_06 AC 111 ms
55,852 KB
testcase_07 AC 111 ms
55,564 KB
testcase_08 AC 112 ms
55,604 KB
testcase_09 AC 115 ms
56,212 KB
testcase_10 AC 123 ms
55,776 KB
testcase_11 AC 124 ms
56,408 KB
testcase_12 AC 123 ms
56,144 KB
testcase_13 AC 124 ms
55,996 KB
testcase_14 AC 121 ms
56,264 KB
testcase_15 AC 121 ms
55,964 KB
testcase_16 AC 122 ms
55,848 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 125 ms
56,108 KB
testcase_20 AC 170 ms
56,244 KB
testcase_21 AC 166 ms
56,368 KB
testcase_22 AC 164 ms
56,520 KB
testcase_23 AC 169 ms
56,048 KB
testcase_24 AC 127 ms
55,780 KB
testcase_25 AC 161 ms
55,856 KB
testcase_26 AC 174 ms
56,064 KB
testcase_27 AC 138 ms
56,240 KB
testcase_28 AC 165 ms
56,348 KB
testcase_29 AC 168 ms
55,996 KB
testcase_30 AC 170 ms
55,824 KB
testcase_31 AC 165 ms
56,568 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