結果

問題 No.370 道路の掃除
ユーザー mitsuomitsuo
提出日時 2016-05-15 21:00:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 186 ms / 2,000 ms
コード長 1,121 bytes
コンパイル時間 2,808 ms
コンパイル使用メモリ 79,196 KB
実行使用メモリ 42,660 KB
最終ジャッジ日時 2024-04-22 17:42:30
合計ジャッジ時間 8,142 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
41,256 KB
testcase_01 AC 113 ms
41,504 KB
testcase_02 AC 124 ms
41,460 KB
testcase_03 AC 114 ms
41,308 KB
testcase_04 AC 129 ms
41,412 KB
testcase_05 AC 127 ms
41,524 KB
testcase_06 AC 125 ms
41,200 KB
testcase_07 AC 123 ms
41,540 KB
testcase_08 AC 124 ms
41,240 KB
testcase_09 AC 127 ms
41,376 KB
testcase_10 AC 135 ms
41,660 KB
testcase_11 AC 135 ms
41,700 KB
testcase_12 AC 132 ms
41,672 KB
testcase_13 AC 133 ms
41,504 KB
testcase_14 AC 133 ms
42,016 KB
testcase_15 AC 133 ms
41,740 KB
testcase_16 AC 131 ms
41,424 KB
testcase_17 AC 134 ms
41,348 KB
testcase_18 AC 142 ms
41,488 KB
testcase_19 AC 138 ms
41,528 KB
testcase_20 AC 175 ms
42,100 KB
testcase_21 AC 178 ms
41,992 KB
testcase_22 AC 173 ms
41,888 KB
testcase_23 AC 165 ms
41,864 KB
testcase_24 AC 137 ms
41,764 KB
testcase_25 AC 157 ms
41,800 KB
testcase_26 AC 174 ms
42,528 KB
testcase_27 AC 160 ms
41,496 KB
testcase_28 AC 173 ms
42,056 KB
testcase_29 AC 179 ms
42,404 KB
testcase_30 AC 184 ms
42,500 KB
testcase_31 AC 172 ms
42,208 KB
testcase_32 AC 162 ms
42,312 KB
testcase_33 AC 186 ms
42,660 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