結果
問題 | No.2730 Two Types Luggage |
ユーザー | tenten |
提出日時 | 2024-04-22 10:26:40 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 863 ms / 2,000 ms |
コード長 | 2,532 bytes |
コンパイル時間 | 2,332 ms |
コンパイル使用メモリ | 79,712 KB |
実行使用メモリ | 89,584 KB |
最終ジャッジ日時 | 2024-04-22 10:27:04 |
合計ジャッジ時間 | 22,357 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 49 ms
36,964 KB |
testcase_01 | AC | 50 ms
37,012 KB |
testcase_02 | AC | 51 ms
36,940 KB |
testcase_03 | AC | 49 ms
37,028 KB |
testcase_04 | AC | 54 ms
37,044 KB |
testcase_05 | AC | 53 ms
37,012 KB |
testcase_06 | AC | 49 ms
36,792 KB |
testcase_07 | AC | 48 ms
37,044 KB |
testcase_08 | AC | 50 ms
36,968 KB |
testcase_09 | AC | 52 ms
37,172 KB |
testcase_10 | AC | 174 ms
43,944 KB |
testcase_11 | AC | 632 ms
68,856 KB |
testcase_12 | AC | 674 ms
89,376 KB |
testcase_13 | AC | 601 ms
66,020 KB |
testcase_14 | AC | 542 ms
68,748 KB |
testcase_15 | AC | 361 ms
52,020 KB |
testcase_16 | AC | 397 ms
54,656 KB |
testcase_17 | AC | 863 ms
88,928 KB |
testcase_18 | AC | 805 ms
87,416 KB |
testcase_19 | AC | 250 ms
45,768 KB |
testcase_20 | AC | 501 ms
55,160 KB |
testcase_21 | AC | 762 ms
68,288 KB |
testcase_22 | AC | 629 ms
89,264 KB |
testcase_23 | AC | 279 ms
46,196 KB |
testcase_24 | AC | 591 ms
56,644 KB |
testcase_25 | AC | 643 ms
68,748 KB |
testcase_26 | AC | 395 ms
51,912 KB |
testcase_27 | AC | 639 ms
67,992 KB |
testcase_28 | AC | 553 ms
55,532 KB |
testcase_29 | AC | 712 ms
87,916 KB |
testcase_30 | AC | 322 ms
46,320 KB |
testcase_31 | AC | 565 ms
66,468 KB |
testcase_32 | AC | 621 ms
65,336 KB |
testcase_33 | AC | 768 ms
89,480 KB |
testcase_34 | AC | 640 ms
89,480 KB |
testcase_35 | AC | 749 ms
89,584 KB |
testcase_36 | AC | 820 ms
89,144 KB |
testcase_37 | AC | 775 ms
89,028 KB |
ソースコード
import java.io.*; import java.util.*; import java.util.function.*; import java.util.stream.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int m = sc.nextInt(); long w = sc.nextLong(); int[] values = new int[n]; for (int i = 0; i < n; i++) { values[i] = sc.nextInt(); } Arrays.sort(values); int[] weight = new int[m]; for (int i = 0; i < m; i++) { weight[i] = sc.nextInt(); } TreeMap<Long, Long> worth = new TreeMap<>(); worth.put(0L, 0L); for (int i = 0; i < m; i++) { int x = sc.nextInt(); Long key = Long.MAX_VALUE; while ((key = worth.lowerKey(key)) != null) { if (worth.floorEntry(key + weight[i]).getValue() >= worth.get(key) + x) { continue; } worth.put(key + weight[i], worth.get(key) + x); Long current = key + weight[i]; while ((current = worth.higherKey(current)) != null) { if (worth.get(current) <= worth.get(key) + x) { worth.remove(current); } else { break; } } } } long ans = worth.floorEntry(w).getValue(); long current = 0; for (int i = 1; i <= n && i <= w; i++) { current += values[n - i]; ans = Math.max(ans, worth.floorEntry(w - i).getValue() + current); } System.out.println(ans); } } class Scanner { BufferedReader br; StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); 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(); } } }