結果

問題 No.370 道路の掃除
ユーザー mitsuomitsuo
提出日時 2016-05-15 21:00:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 190 ms / 2,000 ms
コード長 1,121 bytes
コンパイル時間 2,203 ms
コンパイル使用メモリ 75,768 KB
実行使用メモリ 57,252 KB
最終ジャッジ日時 2023-08-04 19:36:12
合計ジャッジ時間 8,691 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,668 KB
testcase_01 AC 123 ms
55,916 KB
testcase_02 AC 125 ms
55,512 KB
testcase_03 AC 127 ms
56,112 KB
testcase_04 AC 122 ms
55,624 KB
testcase_05 AC 122 ms
55,712 KB
testcase_06 AC 124 ms
55,464 KB
testcase_07 AC 122 ms
55,684 KB
testcase_08 AC 124 ms
55,816 KB
testcase_09 AC 124 ms
55,812 KB
testcase_10 AC 131 ms
56,172 KB
testcase_11 AC 135 ms
55,520 KB
testcase_12 AC 134 ms
55,688 KB
testcase_13 AC 132 ms
56,432 KB
testcase_14 AC 133 ms
55,368 KB
testcase_15 AC 133 ms
55,916 KB
testcase_16 AC 133 ms
55,788 KB
testcase_17 AC 132 ms
56,044 KB
testcase_18 AC 134 ms
56,080 KB
testcase_19 AC 131 ms
56,708 KB
testcase_20 AC 173 ms
56,192 KB
testcase_21 AC 183 ms
56,344 KB
testcase_22 AC 176 ms
56,164 KB
testcase_23 AC 182 ms
56,000 KB
testcase_24 AC 140 ms
56,056 KB
testcase_25 AC 176 ms
56,052 KB
testcase_26 AC 182 ms
56,176 KB
testcase_27 AC 157 ms
55,616 KB
testcase_28 AC 174 ms
56,272 KB
testcase_29 AC 183 ms
54,324 KB
testcase_30 AC 190 ms
56,280 KB
testcase_31 AC 179 ms
56,668 KB
testcase_32 AC 182 ms
57,252 KB
testcase_33 AC 189 ms
56,228 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package jp.fedom.challange.yuki.l2.q370;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

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();
		}
		sc.close();
		System.out.println(solve(N, M, d));
	}

	public static int solve(int N, int M, int[] c) {
		List<Integer> posN = new ArrayList<>();
		List<Integer> negN = new ArrayList<>();
		for (int i : c) {
			if (i < 0) {
				negN.add(i * -1);
			} else {
				posN.add(i);
			}
		}

		Collections.sort(posN);
		Collections.sort(negN);

		int min = Integer.MAX_VALUE;
		for (int pN = 0; pN <= N; pN++) {
			int nN = N - pN;
			if (pN <= posN.size() && nN <= negN.size()) {
				int pd = pN - 1 < 0 ? 0 : posN.get(pN - 1);
				int nd = nN - 1 < 0 ? 0 : negN.get(nN - 1);
				int d = Math.min(pd * 2 + nd, pd + nd * 2);
				min = Math.min(d, min);
			}
		}

		return min;
	}
}
0