結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,080 KB
testcase_01 AC 44 ms
49,628 KB
testcase_02 AC 43 ms
49,892 KB
testcase_03 AC 105 ms
52,692 KB
testcase_04 AC 118 ms
52,376 KB
testcase_05 AC 112 ms
52,440 KB
testcase_06 AC 131 ms
58,160 KB
testcase_07 AC 152 ms
56,972 KB
testcase_08 AC 146 ms
54,768 KB
testcase_09 AC 317 ms
65,312 KB
testcase_10 AC 321 ms
73,140 KB
testcase_11 AC 441 ms
80,548 KB
testcase_12 AC 515 ms
88,944 KB
testcase_13 AC 435 ms
85,380 KB
testcase_14 AC 516 ms
87,288 KB
testcase_15 AC 472 ms
80,544 KB
testcase_16 AC 404 ms
72,932 KB
testcase_17 AC 352 ms
66,260 KB
testcase_18 AC 584 ms
87,124 KB
testcase_19 AC 427 ms
85,376 KB
testcase_20 TLE -
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;
    static int[] sums;
    static int n;
    static int c;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        n = sc.nextInt();
        c = sc.nextInt();
        costs = new int[n];
        for (int i = 0; i < n; i++) {
            costs[i] = sc.nextInt();
        }
        Arrays.sort(costs);
        sums = new int[n];
        sums[0] = costs[0];
        for (int i = 1; i < n; i++) {
            sums[i] = sums[i - 1] + costs[i];
        }
        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[prices.size() + 1][percents.size() + 1];
        System.out.println(dfw(prices.size(), percents.size()));
    }
    
    static int dfw(int pr, int pe) {
        int idx = n - 1 - (c - pr - pe);
        if (idx < 0) {
            return 0;
        }
        if (pr == 0 && pe == 0) {
            return sums[idx];
        }
        if (dp[pr][pe] == 0) {
            if (pr == 0) {
                dp[pr][pe] = dfw(pr, pe - 1) + costs[idx] / 100 * (100 - percents.get(pe - 1));
            } else if (pe == 0) {
                dp[pr][pe] = dfw(pr - 1, pe) + Math.max(0, costs[idx] - prices.get(pr - 1));
            } else {
                dp[pr][pe] = Math.min(dfw(pr, pe - 1) + costs[idx] / 100 * (100 - percents.get(pe - 1)), dfw(pr - 1, pe) + Math.max(0, costs[idx] - prices.get(pr - 1)));
            }
        }
        return dp[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