結果

問題 No.2730 Two Types Luggage
ユーザー hitonanode
提出日時 2024-04-19 22:28:01
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 301 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 1,150 ms
コンパイル使用メモリ 104,576 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-10-11 15:59:42
合計ジャッジ時間 8,472 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using lint = long long;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template <typename T> bool chmax(T &m, const T q) { return m < q ? (m = q, true) : false; }
template <typename T> bool chmin(T &m, const T q) { return m > q ? (m = q, true) : false; }
template <class IStream, class T> IStream &operator>>(IStream &is, std::vector<T> &vec) { for (auto &v : vec) is >> v; return is; }



int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N, M;
    lint W;
    cin >> N >> M >> W;
    vector<lint> A(N), B(M), C(M);
    cin >> A >> B >> C;

    sort(A.rbegin(), A.rend());
    vector<lint> acs(N + 1);
    REP(i, N) acs.at(i + 1) = acs.at(i) + A.at(i);

    lint ret = 0;
    REP(S, 1 << M) {
        lint wsum = 0;
        lint vsum = 0;
        REP(i, M) {
            if ((S >> i) & 1) {
                wsum += B.at(i);
                vsum += C.at(i);

            }
        }
        if (wsum <= W) {
            lint w = W - wsum;
            chmin<lint>(w, N);
            chmax(ret, vsum + acs.at(w));
        }
    }
    cout << ret << '\n';
}
0