結果

問題 No.2730 Two Types Luggage
ユーザー zatsu308zatsu308
提出日時 2024-04-19 21:33:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 1,679 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 170,796 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-04-19 21:34:36
合計ジャッジ時間 7,998 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 5 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 152 ms
14,832 KB
testcase_12 AC 262 ms
18,596 KB
testcase_13 AC 117 ms
12,292 KB
testcase_14 AC 150 ms
15,040 KB
testcase_15 AC 102 ms
6,940 KB
testcase_16 AC 56 ms
7,424 KB
testcase_17 AC 196 ms
18,236 KB
testcase_18 AC 176 ms
16,924 KB
testcase_19 AC 16 ms
6,940 KB
testcase_20 AC 70 ms
8,688 KB
testcase_21 AC 142 ms
14,284 KB
testcase_22 AC 198 ms
18,516 KB
testcase_23 AC 22 ms
6,940 KB
testcase_24 AC 82 ms
9,644 KB
testcase_25 AC 151 ms
15,012 KB
testcase_26 AC 41 ms
6,940 KB
testcase_27 AC 142 ms
14,380 KB
testcase_28 AC 76 ms
9,188 KB
testcase_29 AC 175 ms
16,920 KB
testcase_30 AC 82 ms
6,944 KB
testcase_31 AC 117 ms
12,388 KB
testcase_32 AC 103 ms
11,464 KB
testcase_33 AC 272 ms
18,796 KB
testcase_34 AC 268 ms
18,808 KB
testcase_35 AC 269 ms
18,944 KB
testcase_36 AC 271 ms
18,792 KB
testcase_37 AC 272 ms
18,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll mod = 998244353;

template<ll mod>
struct Mint {
  using M=Mint; ll v;
  M& put(ll x) { v=(x<mod)?x:x-mod; return *this; }
  Mint(ll x=0) { put(x%mod+mod); }
  M operator+(M m) {return M().put(v+m.v);}
  M operator-(M m) {return M().put(v+mod-m.v);}
  M operator*(M m) {return M().put(v*m.v%mod);}
  M operator/(M m) {return M().put(v*m.inv().v%mod);}
// BEGIN IGNORE
  M operator+=(M m) { return put(v+m.v); }
  M operator-=(M m) { return put(v+mod-m.v); }
  M operator*=(M m) { return put(v*m.v%mod); }
  M operator/=(M m) { return put(v*m.inv().v%mod); }
// END IGNORE
  bool operator==(M m) { return v==m.v; }
  M pow(ll m) const {
    M x=v, res=1;
    while (m) {
      if (m&1) res=res*x;
      x=x*x; m>>=1;
    }
    return res;
  }
  M inv() { return pow(mod-2); }
};

using mint = Mint<mod>;

int main(){

  cin.tie(0);
  cin.sync_with_stdio(0);

  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 j = 0; j < m; ++j){
    cin >> b[j];
  }
  for(int i = 0; i < m; ++i){
    cin >> c[i];
  }
  ll ans = 0;
  sort(a.begin(), a.end(), greater<>());
  vector<ll> r(n + 1);
  for(int i = 0; i < n; ++i){
    r[i + 1] = r[i] + a[i];
  }

  auto add = [&](ll rem){
    if(rem < r.size()){
      return r[rem];
    }
    else return r.back();
  };
  for(int i = 0; i < (1 << m); ++i){
    ll wei = 0, val = 0;
    for(int j = 0; j < m; ++j){
      if(i & (1 << j)){
        wei += b[j];
        val += c[j];
      }
    }
    if(wei <= w){
      ans = max(ans, add(w - wei) + val);
    }
  }
  cout << ans << endl;
}
0