結果
問題 |
No.3014 岩井満足性問題
|
ユーザー |
![]() |
提出日時 | 2025-01-28 09:46:00 |
言語 | Java (openjdk 23) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,332 bytes |
コンパイル時間 | 2,848 ms |
コンパイル使用メモリ | 81,064 KB |
実行使用メモリ | 532,672 KB |
最終ジャッジ日時 | 2025-01-28 09:46:10 |
合計ジャッジ時間 | 9,020 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 int[] values; static int[] beauties; 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(); values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); } beauties = new int[n]; for (int i = 0; i < n; i++) { beauties[i] = 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 - beauties[idx])) + values[idx]); } 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(); } } }