結果
| 問題 |
No.1430 Coup de Coupon
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-10-20 08:59:28 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,841 bytes |
| コンパイル時間 | 4,161 ms |
| コンパイル使用メモリ | 80,700 KB |
| 実行使用メモリ | 57,620 KB |
| 最終ジャッジ日時 | 2024-09-20 06:29:56 |
| 合計ジャッジ時間 | 8,166 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 TLE * 1 -- * 17 |
ソースコード
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();
}
}
tenten