結果

問題 No.1430 Coup de Coupon
ユーザー 小野寺健小野寺健
提出日時 2021-05-20 12:31:47
言語 Java21
(openjdk 21)
結果
AC  
実行時間 743 ms / 2,000 ms
コード長 1,636 bytes
コンパイル時間 3,717 ms
コンパイル使用メモリ 80,244 KB
実行使用メモリ 185,272 KB
最終ジャッジ日時 2024-04-18 14:02:05
合計ジャッジ時間 16,216 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
54,088 KB
testcase_01 AC 127 ms
53,892 KB
testcase_02 AC 126 ms
53,984 KB
testcase_03 AC 231 ms
57,932 KB
testcase_04 AC 248 ms
58,464 KB
testcase_05 AC 230 ms
57,588 KB
testcase_06 AC 743 ms
185,212 KB
testcase_07 AC 696 ms
185,272 KB
testcase_08 AC 297 ms
59,048 KB
testcase_09 AC 501 ms
67,892 KB
testcase_10 AC 443 ms
77,108 KB
testcase_11 AC 525 ms
85,356 KB
testcase_12 AC 601 ms
93,432 KB
testcase_13 AC 637 ms
112,360 KB
testcase_14 AC 679 ms
128,620 KB
testcase_15 AC 653 ms
128,400 KB
testcase_16 AC 735 ms
132,708 KB
testcase_17 AC 732 ms
143,008 KB
testcase_18 AC 578 ms
112,708 KB
testcase_19 AC 588 ms
112,476 KB
testcase_20 AC 473 ms
83,780 KB
testcase_21 AC 241 ms
57,424 KB
testcase_22 AC 133 ms
53,996 KB
testcase_23 AC 168 ms
54,264 KB
testcase_24 AC 184 ms
54,196 KB
testcase_25 AC 225 ms
56,812 KB
testcase_26 AC 283 ms
58,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class No1430 {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int C = scan.nextInt();
		List<Integer> P = new ArrayList<Integer>();
		for (int i=0; i < N; i++) {
			P.add(scan.nextInt());
		}
		Collections.sort(P, Collections.reverseOrder());
		List<Integer> TY = new ArrayList<Integer>();
		List<Integer> TP = new ArrayList<Integer>();
		for (int i=0; i < C; i++) {
			int T = scan.nextInt();
			int X = scan.nextInt();
			if (T == 1) {
				TY.add(X);
			} else {
				TP.add(X);
			}
		}
		scan.close();
		Collections.sort(TY, Collections.reverseOrder());
		Collections.sort(TP, Collections.reverseOrder());
		int L = TY.size();
		int[][] DP = new int[N+1][L+1];
		for (int i=0; i <= N; i++) {
			Arrays.fill(DP[i], Integer.MAX_VALUE);
		}
		DP[0][0] = 0;
		for (int i=0; i < N; i++) {
			for (int j=0; j <= L; j++) {
				int price = P.get(i);
				int cost;
				if (i-j < 0) {
					cost = 0;
				} else if (i-j < TP.size()) {
					cost = price * (100 - TP.get(i-j)) / 100;
				} else {
					cost = price;
				}
				DP[i+1][j] = DP[i][j] == Integer.MAX_VALUE ? DP[i+1][j] : Math.min(DP[i+1][j], DP[i][j] + cost);
				if (j < L) {
					cost = price - Math.min(price, TY.get(j));
					DP[i+1][j+1] = DP[i][j] == Integer.MAX_VALUE ? DP[i+1][j+1] : Math.min(DP[i+1][j+1], DP[i][j] + cost);
				}
			}
		}
		int min = Integer.MAX_VALUE;
		for (int j=0; j <=L; j++) {
			min = Math.min(min, DP[N][j]);
		}
		System.out.println(min);
	}
}
0