結果

問題 No.2730 Two Types Luggage
ユーザー ks2mks2m
提出日時 2024-04-19 21:33:06
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,021 ms / 2,000 ms
コード長 1,448 bytes
コンパイル時間 3,238 ms
コンパイル使用メモリ 77,508 KB
実行使用メモリ 131,300 KB
最終ジャッジ日時 2024-04-19 21:33:59
合計ジャッジ時間 25,814 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
36,844 KB
testcase_01 AC 55 ms
37,220 KB
testcase_02 AC 55 ms
36,920 KB
testcase_03 AC 55 ms
37,220 KB
testcase_04 AC 98 ms
38,652 KB
testcase_05 AC 60 ms
37,032 KB
testcase_06 AC 55 ms
37,220 KB
testcase_07 AC 55 ms
36,904 KB
testcase_08 AC 55 ms
36,916 KB
testcase_09 AC 66 ms
37,624 KB
testcase_10 AC 176 ms
45,040 KB
testcase_11 AC 830 ms
117,276 KB
testcase_12 AC 947 ms
130,012 KB
testcase_13 AC 728 ms
105,068 KB
testcase_14 AC 727 ms
105,196 KB
testcase_15 AC 564 ms
60,668 KB
testcase_16 AC 573 ms
66,036 KB
testcase_17 AC 959 ms
126,644 KB
testcase_18 AC 823 ms
127,808 KB
testcase_19 AC 249 ms
49,140 KB
testcase_20 AC 591 ms
78,972 KB
testcase_21 AC 806 ms
103,896 KB
testcase_22 AC 859 ms
129,060 KB
testcase_23 AC 295 ms
49,508 KB
testcase_24 AC 663 ms
83,388 KB
testcase_25 AC 741 ms
118,284 KB
testcase_26 AC 449 ms
63,024 KB
testcase_27 AC 881 ms
104,280 KB
testcase_28 AC 685 ms
77,084 KB
testcase_29 AC 878 ms
121,472 KB
testcase_30 AC 451 ms
49,464 KB
testcase_31 AC 808 ms
104,060 KB
testcase_32 AC 680 ms
85,920 KB
testcase_33 AC 1,002 ms
130,596 KB
testcase_34 AC 897 ms
130,912 KB
testcase_35 AC 1,021 ms
131,300 KB
testcase_36 AC 984 ms
131,012 KB
testcase_37 AC 983 ms
130,968 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