結果

問題 No.1430 Coup de Coupon
ユーザー tentententen
提出日時 2021-04-14 11:16:31
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 2,383 bytes
コンパイル時間 3,310 ms
コンパイル使用メモリ 76,564 KB
実行使用メモリ 747,476 KB
最終ジャッジ日時 2023-09-13 01:14:43
合計ジャッジ時間 9,649 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
50,176 KB
testcase_01 AC 43 ms
49,832 KB
testcase_02 AC 44 ms
49,796 KB
testcase_03 AC 109 ms
54,372 KB
testcase_04 AC 117 ms
53,176 KB
testcase_05 AC 110 ms
52,988 KB
testcase_06 MLE -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main {
    static ArrayList<Integer> percents = new ArrayList<>();
    static ArrayList<Integer> prices = new ArrayList<>();
    static int[][][] dp;
    static int[] costs;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int c = sc.nextInt();
        costs = new int[n];
        for (int i = 0; i < n; i++) {
            costs[i] = sc.nextInt();
        }
        Arrays.sort(costs);
        for (int i = 0; i < c; i++) {
            int type = sc.nextInt();
            int x = sc.nextInt();
            if (type == 1) {
                prices.add(x);
            } else {
                percents.add(x);
            }
        }
        Collections.sort(prices);
        Collections.sort(percents);
        dp = new int[n][prices.size() + 1][percents.size() + 1];
        System.out.println(dfw(n - 1, prices.size(), percents.size()));
    }
    
    static int dfw(int idx, int pr, int pe) {
        if (idx < 0) {
            return 0;
        }
        if (dp[idx][pr][pe] == 0) {
            if (pr == 0 && pe == 0) {
                dp[idx][pr][pe] = dfw(idx - 1, pr, pe) + costs[idx];
            } else if (pr == 0) {
                dp[idx][pr][pe] = dfw(idx - 1, pr, pe - 1) + costs[idx] / 100 * (100 - percents.get(pe - 1));
            } else if (pe == 0) {
                dp[idx][pr][pe] = dfw(idx - 1, pr - 1, pe) + Math.max(0, costs[idx] - prices.get(pr - 1));
            } else {
                dp[idx][pr][pe] = Math.min(dfw(idx - 1, pr, pe - 1) + costs[idx] / 100 * (100 - percents.get(pe - 1)), dfw(idx - 1, pr - 1, pe) + Math.max(0, costs[idx] - prices.get(pr - 1)));
            }
        }
        return dp[idx][pr][pe];
    }
    
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0