結果

問題 No.1430 Coup de Coupon
ユーザー tentententen
提出日時 2021-10-20 08:59:28
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 2,841 bytes
コンパイル時間 4,447 ms
コンパイル使用メモリ 80,304 KB
実行使用メモリ 60,308 KB
最終ジャッジ日時 2023-10-20 10:55:38
合計ジャッジ時間 8,566 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
52,564 KB
testcase_01 AC 54 ms
53,692 KB
testcase_02 AC 54 ms
53,688 KB
testcase_03 AC 135 ms
59,976 KB
testcase_04 AC 125 ms
55,700 KB
testcase_05 AC 115 ms
55,840 KB
testcase_06 AC 159 ms
60,308 KB
testcase_07 AC 188 ms
59,936 KB
testcase_08 AC 170 ms
59,352 KB
testcase_09 TLE -
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<HashMap<Integer, HashMap<Integer, Integer>>> dp = new ArrayList<>();
    static ArrayList<Integer> minus = new ArrayList<>();
    static ArrayList<Integer> rates = new ArrayList<>();
    static int[] prices;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int c = sc.nextInt();
        prices = new int[n];
        for (int i = 0; i < n; i++) {
            prices[i] = sc.nextInt();
            dp.add(new HashMap<>());
        }
        Arrays.sort(prices);
        for (int i = 0; i < c; i++) {
            if (sc.nextInt() == 1) {
                minus.add(sc.nextInt());
            } else {
                rates.add(sc.nextInt());
            }
        }
        Collections.sort(minus);
        Collections.sort(rates);
        System.out.println(dfw(n - 1, minus.size(), rates.size()));
    }
    
    static int dfw(int idx, int mIdx, int rIdx) {
        if (idx < 0) {
            return 0;
        }
        if (!dp.get(idx).containsKey(mIdx)) {
            dp.get(idx).put(mIdx, new HashMap<>());
        }
        if (dp.get(idx).get(mIdx).containsKey(rIdx)) {
            return dp.get(idx).get(mIdx).get(rIdx);
        }
        int ans;
        if (mIdx == 0) {
            if (rIdx == 0) {
                ans = prices[idx] + dfw(idx - 1, 0, 0);
            } else {
                ans = getRate(prices[idx], rates.get(rIdx - 1)) + dfw(idx - 1, 0, rIdx - 1);
            }
        } else {
            if (rIdx == 0) {
                ans = getMinus(prices[idx], minus.get(mIdx - 1)) + dfw(idx - 1, mIdx - 1, 0);
            } else {
                ans = Math.min(getRate(prices[idx], rates.get(rIdx - 1)) + dfw(idx - 1, mIdx, rIdx - 1), getMinus(prices[idx], minus.get(mIdx - 1)) + dfw(idx - 1, mIdx - 1, rIdx));
            }
        }
        dp.get(idx).get(mIdx).put(rIdx, ans);
        return ans;
    }
    
    static int getRate(int p, int r) {
        return p / 100 * (100 - r);
    }
    
    static int getMinus(int p, int m) {
        return Math.max(0, p - m);
    }
}
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 nextLine() throws Exception {
        return br.readLine();
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0