結果
問題 | No.2730 Two Types Luggage |
ユーザー |
|
提出日時 | 2024-04-19 22:32:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 557 ms / 2,000 ms |
コード長 | 1,376 bytes |
コンパイル時間 | 3,997 ms |
コンパイル使用メモリ | 234,656 KB |
実行使用メモリ | 18,996 KB |
最終ジャッジ日時 | 2024-10-11 16:08:17 |
合計ジャッジ時間 | 15,857 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; using ull = unsigned long long; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } const vector<int> dx = {0,0,1,-1}; const vector<int> dy = {1,-1,0,0}; const ll INF = 1e18; const ll inf = 1e8; const ll MOD = 998244353; int main(){ 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.rbegin(),a.rend()); vector<ll> s(n); s[0] = a[0]; for(int i = 1; i < n; i++) s[i] = s[i-1] + a[i]; ll ans = -1; for (int bit = 0; bit < (1 << m); ++bit) { ll p = w, v = 0; for (int i = 0; i < m; ++i) { if (bit & (1 << i)) { p -= b[i]; v += c[i]; } } if(p<0) break; if(p>=n){ v += s[n-1]; }else if(p==0){ ; } else{ v += s[p-1]; } if(v == 127){ cout << p << endl; return 0; } chmax(ans,v); } cout << ans << endl; }