結果
問題 | No.2730 Two Types Luggage |
ユーザー |
![]() |
提出日時 | 2024-04-22 10:26:40 |
言語 | Java (openjdk 23) |
結果 |
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 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
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();}}}