結果

問題 No.2730 Two Types Luggage
ユーザー ks2mks2m
提出日時 2024-04-19 21:32:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 929 ms / 2,000 ms
コード長 1,448 bytes
コンパイル時間 2,478 ms
コンパイル使用メモリ 78,296 KB
実行使用メモリ 142,516 KB
最終ジャッジ日時 2024-04-19 21:33:21
合計ジャッジ時間 23,360 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 48 ms
50,024 KB
testcase_01 AC 46 ms
50,204 KB
testcase_02 AC 46 ms
50,180 KB
testcase_03 AC 47 ms
50,452 KB
testcase_04 AC 85 ms
52,264 KB
testcase_05 AC 52 ms
50,568 KB
testcase_06 AC 49 ms
50,272 KB
testcase_07 AC 48 ms
50,356 KB
testcase_08 AC 47 ms
50,184 KB
testcase_09 AC 57 ms
50,580 KB
testcase_10 AC 157 ms
56,148 KB
testcase_11 AC 721 ms
127,988 KB
testcase_12 AC 837 ms
141,732 KB
testcase_13 AC 651 ms
119,276 KB
testcase_14 AC 615 ms
118,360 KB
testcase_15 AC 499 ms
70,600 KB
testcase_16 AC 426 ms
77,152 KB
testcase_17 AC 837 ms
137,524 KB
testcase_18 AC 693 ms
139,728 KB
testcase_19 AC 230 ms
60,648 KB
testcase_20 AC 569 ms
93,120 KB
testcase_21 AC 764 ms
118,124 KB
testcase_22 AC 725 ms
139,524 KB
testcase_23 AC 241 ms
60,916 KB
testcase_24 AC 630 ms
95,848 KB
testcase_25 AC 669 ms
128,840 KB
testcase_26 AC 441 ms
72,044 KB
testcase_27 AC 683 ms
118,172 KB
testcase_28 AC 546 ms
85,988 KB
testcase_29 AC 746 ms
132,504 KB
testcase_30 AC 387 ms
61,068 KB
testcase_31 AC 679 ms
116,544 KB
testcase_32 AC 648 ms
98,016 KB
testcase_33 AC 929 ms
141,292 KB
testcase_34 AC 802 ms
141,296 KB
testcase_35 AC 868 ms
141,348 KB
testcase_36 AC 886 ms
141,552 KB
testcase_37 AC 849 ms
142,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		long w = Long.parseLong(sa[2]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int[] b = new int[m];
		for (int i = 0; i < m; i++) {
			b[i] = Integer.parseInt(sa[i]);
		}
		sa = br.readLine().split(" ");
		int[] c = new int[m];
		for (int i = 0; i < m; i++) {
			c[i] = Integer.parseInt(sa[i]);
		}
		br.close();

		Arrays.sort(a);
		reverse(a);
		long[] a2 = new long[n + 1];
		for (int i = 0; i < n; i++) {
			a2[i + 1] = a2[i] + a[i];
		}

		long ans = 0;
		int end = 1 << m;
		for (int i = 0; i < end; i++) {
			long wei = 0;
			long val = 0;
			for (int j = 0; j < m; j++) {
				if ((i >> j & 1) == 1) {
					wei += b[j];
					val += c[j];
				}
			}
			if (wei <= w) {
				int rem = (int) Math.min(n, w - wei);
				val += a2[rem];
				ans = Math.max(ans, val);
			}
		}
		System.out.println(ans);
	}

	static void reverse(int[] a) {
		for (int i = 0; i < a.length / 2; i++) {
			int tmp = a[i];
			a[i] = a[a.length - 1 - i];
			a[a.length - 1 - i] = tmp;
		}
	}
}
0