結果
問題 | No.1163 I want to be a high achiever |
ユーザー | tenten |
提出日時 | 2021-12-01 14:30:00 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 135 ms / 2,000 ms |
コード長 | 2,110 bytes |
コンパイル時間 | 2,129 ms |
コンパイル使用メモリ | 77,400 KB |
実行使用メモリ | 58,192 KB |
最終ジャッジ日時 | 2023-09-17 19:55:55 |
合計ジャッジ時間 | 6,104 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 44 ms
49,260 KB |
testcase_01 | AC | 45 ms
49,140 KB |
testcase_02 | AC | 44 ms
49,200 KB |
testcase_03 | AC | 44 ms
49,412 KB |
testcase_04 | AC | 104 ms
55,404 KB |
testcase_05 | AC | 81 ms
52,448 KB |
testcase_06 | AC | 130 ms
58,180 KB |
testcase_07 | AC | 64 ms
50,288 KB |
testcase_08 | AC | 60 ms
50,376 KB |
testcase_09 | AC | 108 ms
57,852 KB |
testcase_10 | AC | 106 ms
55,488 KB |
testcase_11 | AC | 84 ms
52,792 KB |
testcase_12 | AC | 102 ms
55,952 KB |
testcase_13 | AC | 129 ms
58,136 KB |
testcase_14 | AC | 135 ms
57,872 KB |
testcase_15 | AC | 77 ms
52,552 KB |
testcase_16 | AC | 106 ms
55,508 KB |
testcase_17 | AC | 93 ms
53,452 KB |
testcase_18 | AC | 66 ms
50,120 KB |
testcase_19 | AC | 132 ms
58,192 KB |
testcase_20 | AC | 132 ms
57,852 KB |
testcase_21 | AC | 106 ms
57,772 KB |
testcase_22 | AC | 97 ms
53,404 KB |
testcase_23 | AC | 97 ms
53,136 KB |
testcase_24 | AC | 58 ms
51,492 KB |
testcase_25 | AC | 125 ms
55,484 KB |
testcase_26 | AC | 53 ms
49,388 KB |
testcase_27 | AC | 44 ms
49,232 KB |
testcase_28 | AC | 43 ms
49,192 KB |
testcase_29 | AC | 53 ms
49,420 KB |
testcase_30 | AC | 43 ms
49,156 KB |
testcase_31 | AC | 45 ms
49,308 KB |
testcase_32 | AC | 44 ms
49,164 KB |
ソースコード
import java.io.*; import java.util.*; public class Main { static ArrayList<Integer> points = new ArrayList<>(); static ArrayList<Integer> costs = new ArrayList<>(); static int[][] dp; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int x = sc.nextInt(); int[] values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt() - x; } int total = 0; for (int i = 0; i < n; i++) { int c = sc.nextInt(); if (values[i] >= 0) { total += values[i]; } else { points.add(values[i]); costs.add(c); } } if (points.size() == n) { System.out.println(-1); return; } dp = new int[points.size()][total + 1]; for (int[] arr : dp) { Arrays.fill(arr, -1); } System.out.println(dfw(points.size() - 1, total)); } static int dfw(int idx, int price) { if (price < 0) { return Integer.MAX_VALUE / 2; } if (idx < 0) { return 0; } if (dp[idx][price] < 0) { dp[idx][price] = Math.min(dfw(idx - 1, price) + costs.get(idx), dfw(idx - 1, price + points.get(idx))); } return dp[idx][price]; } } 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 next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }