結果

問題 No.370 道路の掃除
ユーザー hhgfhn1hhgfhn1
提出日時 2018-12-21 16:51:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 2,852 bytes
コンパイル時間 2,245 ms
コンパイル使用メモリ 77,992 KB
実行使用メモリ 53,288 KB
最終ジャッジ日時 2023-10-26 01:32:49
合計ジャッジ時間 5,625 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
53,268 KB
testcase_01 AC 54 ms
53,264 KB
testcase_02 AC 55 ms
53,276 KB
testcase_03 AC 54 ms
53,264 KB
testcase_04 AC 54 ms
53,276 KB
testcase_05 AC 57 ms
52,172 KB
testcase_06 AC 55 ms
52,164 KB
testcase_07 AC 55 ms
53,268 KB
testcase_08 AC 55 ms
53,272 KB
testcase_09 AC 54 ms
53,268 KB
testcase_10 AC 55 ms
53,268 KB
testcase_11 AC 55 ms
52,204 KB
testcase_12 AC 56 ms
52,240 KB
testcase_13 AC 55 ms
51,224 KB
testcase_14 AC 55 ms
52,220 KB
testcase_15 AC 56 ms
52,152 KB
testcase_16 AC 56 ms
53,272 KB
testcase_17 AC 54 ms
52,212 KB
testcase_18 AC 54 ms
53,280 KB
testcase_19 AC 57 ms
53,268 KB
testcase_20 AC 58 ms
52,212 KB
testcase_21 AC 55 ms
53,280 KB
testcase_22 AC 57 ms
52,224 KB
testcase_23 AC 56 ms
53,276 KB
testcase_24 AC 56 ms
53,276 KB
testcase_25 AC 56 ms
53,280 KB
testcase_26 AC 56 ms
53,272 KB
testcase_27 AC 55 ms
52,188 KB
testcase_28 AC 56 ms
53,268 KB
testcase_29 AC 56 ms
52,200 KB
testcase_30 AC 56 ms
53,288 KB
testcase_31 AC 55 ms
53,284 KB
testcase_32 AC 57 ms
51,240 KB
testcase_33 AC 57 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int m=scanner.nextInt();
		int[] d=new int[m];
		for(int i=0;i<m;i++) {
			d[i]=scanner.nextInt();
		}
		Arrays.sort(d);
		int min=Integer.MAX_VALUE;
		for(int i=0;i<m-n+1;i++) {
			int k=0;
			int tmp1=d[i];
			int tmp2=d[i+n-1];
			if(tmp1<0==tmp2<0) {
				k=Math.max(Math.abs(tmp1), Math.abs(tmp2));
			}else {
				int a=Math.max(Math.abs(tmp1), Math.abs(tmp2));
				int b=Math.min(Math.abs(tmp1), Math.abs(tmp2));
				k=Math.abs(a+b*2);
			}
			min=Math.min(k, min);
		}
		System.out.println(min);
	}
}


class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
0