結果

問題 No.370 道路の掃除
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-11-16 17:56:01
言語 Java
(openjdk 23)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 787 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 77,544 KB
実行使用メモリ 42,504 KB
最終ジャッジ日時 2024-11-26 02:20:31
合計ジャッジ時間 8,646 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

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