結果

問題 No.370 道路の掃除
ユーザー t8m8⛄️t8m8⛄️
提出日時 2016-08-17 15:22:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 204 ms / 2,000 ms
コード長 1,061 bytes
コンパイル時間 3,394 ms
コンパイル使用メモリ 78,132 KB
実行使用メモリ 58,736 KB
最終ジャッジ日時 2023-08-07 14:38:38
合計ジャッジ時間 10,302 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
55,836 KB
testcase_01 AC 136 ms
55,920 KB
testcase_02 AC 137 ms
56,824 KB
testcase_03 AC 135 ms
55,988 KB
testcase_04 AC 135 ms
56,108 KB
testcase_05 AC 137 ms
56,532 KB
testcase_06 AC 136 ms
55,932 KB
testcase_07 AC 136 ms
56,468 KB
testcase_08 AC 137 ms
55,980 KB
testcase_09 AC 137 ms
56,388 KB
testcase_10 AC 144 ms
56,440 KB
testcase_11 AC 145 ms
56,228 KB
testcase_12 AC 144 ms
56,064 KB
testcase_13 AC 145 ms
56,180 KB
testcase_14 AC 144 ms
56,624 KB
testcase_15 AC 144 ms
56,068 KB
testcase_16 AC 143 ms
56,300 KB
testcase_17 AC 143 ms
56,676 KB
testcase_18 AC 145 ms
56,824 KB
testcase_19 AC 146 ms
56,404 KB
testcase_20 AC 193 ms
56,644 KB
testcase_21 AC 198 ms
56,468 KB
testcase_22 AC 193 ms
56,604 KB
testcase_23 AC 197 ms
56,724 KB
testcase_24 AC 152 ms
56,660 KB
testcase_25 AC 192 ms
58,464 KB
testcase_26 AC 200 ms
56,936 KB
testcase_27 AC 162 ms
56,144 KB
testcase_28 AC 178 ms
56,644 KB
testcase_29 AC 202 ms
56,904 KB
testcase_30 AC 204 ms
56,684 KB
testcase_31 AC 193 ms
56,744 KB
testcase_32 AC 204 ms
56,780 KB
testcase_33 AC 202 ms
58,736 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class No0370 {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		int[] d = new int[m];
		for (int i=0; i<m; i++) {
			d[i] = in.nextInt();
		}
		Arrays.sort(d);
		int ans = Integer.MAX_VALUE/2;
		int l = 0, r = n-1;
		while (r < m) {
			if (d[r] <= 0) {
				ans = Math.min(ans, -d[l]);
			} else if (0 <= d[l]) {
				ans = Math.min(ans, d[r]);
			} else {
				ans = Math.min(ans, Math.min(-2*d[l] + d[r], -d[l] + 2*d[r]));
			}
			l++; r++;
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.nanoTime();

		solve();
		out.flush();

		long end = System.nanoTime();
		dump((end - start) / 1000000 + " ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}
0