結果
問題 | No.1163 I want to be a high achiever |
ユーザー | tenten |
提出日時 | 2021-11-05 15:09:15 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,465 bytes |
コンパイル時間 | 2,242 ms |
コンパイル使用メモリ | 78,196 KB |
実行使用メモリ | 114,828 KB |
最終ジャッジ日時 | 2024-11-06 05:33:19 |
合計ジャッジ時間 | 8,623 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 57 ms
50,240 KB |
testcase_01 | AC | 57 ms
50,420 KB |
testcase_02 | AC | 58 ms
50,424 KB |
testcase_03 | AC | 57 ms
50,608 KB |
testcase_04 | AC | 188 ms
76,684 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 58 ms
50,352 KB |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | AC | 139 ms
62,076 KB |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 61 ms
50,512 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 60 ms
50,632 KB |
testcase_27 | AC | 56 ms
50,376 KB |
testcase_28 | AC | 57 ms
50,056 KB |
testcase_29 | WA | - |
testcase_30 | AC | 57 ms
50,652 KB |
testcase_31 | AC | 57 ms
50,000 KB |
testcase_32 | AC | 59 ms
50,448 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static Point[] points; static int[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int x = sc.nextInt(); points = new Point[n]; int total = 0; boolean enable = false; for (int i = 0; i < n; i++) { points[i] = new Point(x - sc.nextInt()); total += points[i].value; enable |= (points[i].value <= 0); } if (!enable) { System.out.println(-1); return; } if (total <= 0) { System.out.println(0); return; } for (int i = 0; i < n; i++) { points[i].cost = sc.nextInt(); } Arrays.sort(points); dp = new int[n][total + 1]; for (int[] arr : dp) { Arrays.fill(arr, -1); } System.out.println(dfw(n - 1, total)); } static int dfw(int idx, int total) { if (total < 0) { return 0; } if (idx < 0 || points[idx].value <= 0) { return Integer.MAX_VALUE / 2; } if (dp[idx][total] < 0) { dp[idx][total] = Math.min(dfw(idx - 1, total), dfw(idx - 1, total - points[idx].value) + points[idx].cost); } return dp[idx][total]; } static class Point implements Comparable<Point> { int value; int cost; public Point(int value) { this.value = value; } public int compareTo(Point p) { return value - p.value; } } } 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 double nextDouble() throws Exception { return Double.parseDouble(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(); } }