結果
| 問題 |
No.1430 Coup de Coupon
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-05-20 12:31:47 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 854 ms / 2,000 ms |
| コード長 | 1,636 bytes |
| コンパイル時間 | 4,362 ms |
| コンパイル使用メモリ | 80,744 KB |
| 実行使用メモリ | 185,360 KB |
| 最終ジャッジ日時 | 2024-10-10 07:14:03 |
| 合計ジャッジ時間 | 17,588 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
public class No1430 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int C = scan.nextInt();
List<Integer> P = new ArrayList<Integer>();
for (int i=0; i < N; i++) {
P.add(scan.nextInt());
}
Collections.sort(P, Collections.reverseOrder());
List<Integer> TY = new ArrayList<Integer>();
List<Integer> TP = new ArrayList<Integer>();
for (int i=0; i < C; i++) {
int T = scan.nextInt();
int X = scan.nextInt();
if (T == 1) {
TY.add(X);
} else {
TP.add(X);
}
}
scan.close();
Collections.sort(TY, Collections.reverseOrder());
Collections.sort(TP, Collections.reverseOrder());
int L = TY.size();
int[][] DP = new int[N+1][L+1];
for (int i=0; i <= N; i++) {
Arrays.fill(DP[i], Integer.MAX_VALUE);
}
DP[0][0] = 0;
for (int i=0; i < N; i++) {
for (int j=0; j <= L; j++) {
int price = P.get(i);
int cost;
if (i-j < 0) {
cost = 0;
} else if (i-j < TP.size()) {
cost = price * (100 - TP.get(i-j)) / 100;
} else {
cost = price;
}
DP[i+1][j] = DP[i][j] == Integer.MAX_VALUE ? DP[i+1][j] : Math.min(DP[i+1][j], DP[i][j] + cost);
if (j < L) {
cost = price - Math.min(price, TY.get(j));
DP[i+1][j+1] = DP[i][j] == Integer.MAX_VALUE ? DP[i+1][j+1] : Math.min(DP[i+1][j+1], DP[i][j] + cost);
}
}
}
int min = Integer.MAX_VALUE;
for (int j=0; j <=L; j++) {
min = Math.min(min, DP[N][j]);
}
System.out.println(min);
}
}