結果
| 問題 |
No.1430 Coup de Coupon
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-04-14 11:31:43 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,502 bytes |
| コンパイル時間 | 2,280 ms |
| コンパイル使用メモリ | 80,020 KB |
| 実行使用メモリ | 90,624 KB |
| 最終ジャッジ日時 | 2024-06-30 12:15:45 |
| 合計ジャッジ時間 | 11,742 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 TLE * 1 -- * 6 |
ソースコード
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();
}
}
tenten