結果

問題 No.2730 Two Types Luggage
ユーザー otamay6otamay6
提出日時 2024-04-20 17:51:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 583 ms / 2,000 ms
コード長 1,016 bytes
コンパイル時間 861 ms
コンパイル使用メモリ 87,440 KB
実行使用メモリ 31,604 KB
最終ジャッジ日時 2024-04-20 17:52:13
合計ジャッジ時間 12,517 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 7 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 15 ms
5,376 KB
testcase_11 AC 352 ms
11,904 KB
testcase_12 AC 557 ms
31,604 KB
testcase_13 AC 301 ms
10,112 KB
testcase_14 AC 348 ms
11,904 KB
testcase_15 AC 181 ms
22,304 KB
testcase_16 AC 125 ms
6,656 KB
testcase_17 AC 469 ms
14,336 KB
testcase_18 AC 414 ms
13,568 KB
testcase_19 AC 38 ms
5,376 KB
testcase_20 AC 164 ms
7,424 KB
testcase_21 AC 332 ms
11,392 KB
testcase_22 AC 477 ms
14,720 KB
testcase_23 AC 46 ms
5,468 KB
testcase_24 AC 188 ms
8,576 KB
testcase_25 AC 351 ms
12,288 KB
testcase_26 AC 98 ms
5,632 KB
testcase_27 AC 345 ms
11,520 KB
testcase_28 AC 171 ms
7,808 KB
testcase_29 AC 408 ms
13,440 KB
testcase_30 AC 135 ms
20,972 KB
testcase_31 AC 295 ms
10,240 KB
testcase_32 AC 240 ms
9,344 KB
testcase_33 AC 559 ms
31,512 KB
testcase_34 AC 582 ms
31,508 KB
testcase_35 AC 563 ms
31,488 KB
testcase_36 AC 583 ms
31,512 KB
testcase_37 AC 558 ms
31,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

int main(){
	int n, m;
	long long w;
	std::cin>>n>>m>>w;
	std::vector<int> a(n);
	std::vector<int> b(m);
	std::vector<int> c(m);
	for(int i = 0; i < n; i++){
		std::cin>>a[i];
	}
	for(int i = 0; i < m; i++){
		std::cin>>b[i];
	}
	for(int i = 0; i < m; i++){
		std::cin>>c[i];
	}
	std::sort(a.rbegin(), a.rend());
	std::vector<long long> sum(n+1);
	for(int i = 0; i < n; i++){
		sum[i+1] = sum[i] + a[i];
	}
	// タイプYを選ぶ全パターン列挙
	typedef struct {
		long long weight;
		long long cost;
	} knapsack_t;
	std::vector<knapsack_t> patterns;
	for(int bit = 0; bit < (1<<m); bit++){
		knapsack_t knapsack = {};
		for(int i = 0; i < m; i++) if(bit>>i&1){
			knapsack.weight += b[i];
			knapsack.cost += c[i];
		}
		patterns.push_back(knapsack);
	}
	long long ans = 0;
	for(auto p: patterns) if(p.weight <= w){
		int remain = std::min(w-p.weight, (long long)n);
		ans = std::max(ans, p.cost + sum[remain]);
	}
	std::cout << ans << std::endl;
}
0