結果

問題 No.2730 Two Types Luggage
ユーザー otoshigootoshigo
提出日時 2024-04-19 21:30:04
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 282 ms / 2,000 ms
コード長 1,050 bytes
コンパイル時間 2,408 ms
コンパイル使用メモリ 207,416 KB
実行使用メモリ 18,816 KB
最終ジャッジ日時 2024-10-11 14:04:53
合計ジャッジ時間 8,967 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int N,M;
    ll 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];
    ll ans=0;
    sort(rall(A));
    vector<ll>S(N+1);
    for(int i=0;i<N;i++)S[i+1]=S[i]+A[i];
    for(int bit=0;bit<1<<M;bit++){
        ll wt=0,cost=0;
        for(int i=0;i<M;i++){
            if(bit>>i&1){
                wt+=B[i];
                cost+=C[i];
            }
        }
        if(wt>W)continue;
        cost+=S[min((ll)N,W-wt)];
        chmax(ans,cost);
    }
    cout<<ans<<"\n";
}
0