結果

問題 No.2730 Two Types Luggage
ユーザー ooaiuooaiu
提出日時 2024-08-10 18:14:38
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 562 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 3,917 ms
コンパイル使用メモリ 252,424 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-08-10 18:14:59
合計ジャッジ時間 19,518 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

#ifdef LOCAL
#include "../algo/debug.hpp"
#else
#define debug(...) void(0)
#endif

void solve() {
    ll n, m, w; cin >> n >> m >> w;
    vector<ll> a(n), b(m), c(m);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < m; i++) cin >> b[i];
    for(int i = 0; i < m; i++) cin >> c[i];
    sort(a.begin(), a.end(), greater<>{});
    vector<ll> pref(n + 1, 0);
    for(int i = 0; i < n; i++) pref[i + 1] = pref[i] + a[i];
    ll ans = 0;
    for(int bit = 0; bit < (1 << m); bit++) {
        ll nowb{}, nowc{};
        for(int i = 0; i < m; i++) {
            if(bit & (1 << i)) {
                nowb += b[i];
                nowc += c[i];
            }
        }
        if(nowb <= w) {
            ll rt = w - nowb;
            ans = max(ans, nowc + pref[min(rt, n)]);
        }
    }
    cout << ans << endl;
}

int main() {
    int T = 1;
    // cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}
0