結果

問題 No.798 コレクション
ユーザー 37zigen37zigen
提出日時 2018-08-05 19:38:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 399 ms / 2,000 ms
コード長 1,178 bytes
コンパイル時間 2,180 ms
コンパイル使用メモリ 75,856 KB
実行使用メモリ 91,628 KB
最終ジャッジ日時 2023-09-11 02:23:59
合計ジャッジ時間 9,119 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,868 KB
testcase_01 AC 122 ms
55,900 KB
testcase_02 AC 125 ms
56,156 KB
testcase_03 AC 124 ms
56,180 KB
testcase_04 AC 123 ms
55,912 KB
testcase_05 AC 124 ms
55,900 KB
testcase_06 AC 125 ms
55,740 KB
testcase_07 AC 125 ms
55,964 KB
testcase_08 AC 124 ms
55,840 KB
testcase_09 AC 124 ms
56,232 KB
testcase_10 AC 124 ms
56,304 KB
testcase_11 AC 125 ms
56,380 KB
testcase_12 AC 123 ms
56,240 KB
testcase_13 AC 293 ms
71,064 KB
testcase_14 AC 345 ms
83,616 KB
testcase_15 AC 331 ms
74,284 KB
testcase_16 AC 256 ms
63,900 KB
testcase_17 AC 306 ms
71,680 KB
testcase_18 AC 392 ms
91,460 KB
testcase_19 AC 353 ms
83,464 KB
testcase_20 AC 262 ms
67,404 KB
testcase_21 AC 254 ms
63,612 KB
testcase_22 AC 337 ms
74,440 KB
testcase_23 AC 124 ms
56,156 KB
testcase_24 AC 369 ms
91,268 KB
testcase_25 AC 399 ms
91,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[][] A = new long[N][2];
		for (int i = 0; i < N; ++i) {
			A[i][0] = sc.nextLong();
			A[i][1] = sc.nextLong();
		}
		Arrays.sort(A, new Comparator<long[]>() {
			@Override
			public int compare(long[] o1, long[] o2) {
				return -Long.compare(o1[1], o2[1]);
			}
		});
		long[][] dp = new long[N + 1][N + 1];
		for (int i = 0; i < dp.length; ++i)
			for (int j = 0; j < dp[i].length; ++j)
				dp[i][j] = Long.MAX_VALUE / 3;
		dp[0][0] = 0;
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j <= N; ++j) {
				if (j + 1 <= N)
					dp[i + 1][j + 1] = Math.min(dp[i + 1][j + 1], dp[i][j] + A[i][0] + A[i][1] * j);
				dp[i + 1][j] = Math.min(dp[i + 1][j], dp[i][j]);
			}
		}
		int sub = 0;
		for (int i = 0, res = N; res > 0; ++i) {
			--res;
			if (i % 2 == 1 && res > 0) {
				--res;
				++sub;
			}
		}
		System.out.println(dp[N][N - sub]);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0