結果
問題 | No.2730 Two Types Luggage |
ユーザー | tenten |
提出日時 | 2024-04-22 10:26:40 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 879 ms / 2,000 ms |
コード長 | 2,532 bytes |
コンパイル時間 | 3,923 ms |
コンパイル使用メモリ | 79,480 KB |
実行使用メモリ | 90,228 KB |
最終ジャッジ日時 | 2024-10-14 09:42:12 |
合計ジャッジ時間 | 23,512 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 50 ms
36,940 KB |
testcase_01 | AC | 51 ms
36,940 KB |
testcase_02 | AC | 51 ms
37,184 KB |
testcase_03 | AC | 51 ms
37,100 KB |
testcase_04 | AC | 53 ms
37,196 KB |
testcase_05 | AC | 52 ms
37,132 KB |
testcase_06 | AC | 51 ms
37,152 KB |
testcase_07 | AC | 49 ms
37,220 KB |
testcase_08 | AC | 50 ms
36,792 KB |
testcase_09 | AC | 52 ms
36,980 KB |
testcase_10 | AC | 177 ms
43,252 KB |
testcase_11 | AC | 663 ms
68,720 KB |
testcase_12 | AC | 682 ms
89,604 KB |
testcase_13 | AC | 635 ms
66,820 KB |
testcase_14 | AC | 598 ms
68,876 KB |
testcase_15 | AC | 347 ms
51,148 KB |
testcase_16 | AC | 392 ms
55,064 KB |
testcase_17 | AC | 820 ms
88,420 KB |
testcase_18 | AC | 677 ms
88,208 KB |
testcase_19 | AC | 243 ms
45,516 KB |
testcase_20 | AC | 492 ms
54,744 KB |
testcase_21 | AC | 696 ms
68,292 KB |
testcase_22 | AC | 651 ms
89,376 KB |
testcase_23 | AC | 278 ms
46,248 KB |
testcase_24 | AC | 564 ms
56,824 KB |
testcase_25 | AC | 599 ms
69,124 KB |
testcase_26 | AC | 388 ms
51,972 KB |
testcase_27 | AC | 700 ms
68,892 KB |
testcase_28 | AC | 523 ms
55,436 KB |
testcase_29 | AC | 700 ms
87,552 KB |
testcase_30 | AC | 286 ms
46,408 KB |
testcase_31 | AC | 595 ms
65,876 KB |
testcase_32 | AC | 634 ms
65,156 KB |
testcase_33 | AC | 748 ms
89,456 KB |
testcase_34 | AC | 624 ms
90,228 KB |
testcase_35 | AC | 813 ms
90,076 KB |
testcase_36 | AC | 879 ms
89,700 KB |
testcase_37 | AC | 747 ms
90,008 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(); } } }