結果
| 問題 | No.3014 岩井満足性問題 |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2025-01-28 09:41:41 |
| 言語 | Java (openjdk 23) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,332 bytes |
| 記録 | |
| コンパイル時間 | 2,755 ms |
| コンパイル使用メモリ | 81,244 KB |
| 実行使用メモリ | 532,608 KB |
| 最終ジャッジ日時 | 2025-01-28 09:41:51 |
| 合計ジャッジ時間 | 8,636 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 MLE * 3 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
static Question[] questions;
static long[][][] dp;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int d = sc.nextInt();
int k = sc.nextInt();
questions = new Question[n];
for (int i = 0; i < n; i++) {
questions[i] = new Question(sc.nextInt());
}
for (int i = 0; i < n; i++) {
questions[i].beauty = sc.nextInt();
}
dp = new long[n][d][k + 1];
for (long[][] arr1 : dp) {
for (long[] arr2 : arr1) {
Arrays.fill(arr2, Long.MIN_VALUE);
}
}
long ans = dfw(n - 1, d - 1, k);
System.out.println(ans <= Long.MIN_VALUE / 3 ? "No" : String.valueOf(ans));
}
static long dfw(int idx, int v, int w) {
if (v < 0) {
return w == 0 ? 0 : Long.MIN_VALUE / 2;
}
if (idx < 0) {
return Long.MIN_VALUE / 2;
}
if (dp[idx][v][w] == Long.MIN_VALUE) {
dp[idx][v][w] = Math.max(dfw(idx - 1, v, w), dfw(idx - 1, v - 1, Math.max(0, w - questions[idx].beauty)) + questions[idx].value);
}
return dp[idx][v][w];
}
static class Question {
int value;
int beauty;
public Question(int value) {
this.value = value;
}
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten