結果

問題 No.2730 Two Types Luggage
ユーザー ks2m
提出日時 2024-04-19 21:32:55
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,014 ms / 2,000 ms
コード長 1,448 bytes
コンパイル時間 4,834 ms
コンパイル使用メモリ 77,268 KB
実行使用メモリ 131,116 KB
最終ジャッジ日時 2024-10-11 14:11:58
合計ジャッジ時間 28,511 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

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