結果
問題 |
No.2730 Two Types Luggage
|
ユーザー |
|
提出日時 | 2024-04-27 15:48:04 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 743 ms / 2,000 ms |
コード長 | 1,895 bytes |
コンパイル時間 | 2,484 ms |
コンパイル使用メモリ | 200,444 KB |
最終ジャッジ日時 | 2025-02-21 09:14:58 |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for(int i=0; i<n; i++) #define debug 0 #define YES cout << "Yes" << endl; #define NO cout << "No" << endl; using ll = long long; using ld = long double; const int mod = 998244353; const int MOD = 1000000007; const double pi = atan2(0, -1); const int inf = 1 << 31 - 1; const ll INF = 1LL << 63-1; #include <time.h> #include <chrono> //vectorの中身を空白区切りで出力 template<typename T> void print1(vector<T> v) { for (int i = 0; i < v.size(); i++) { cout << v[i]; if (i < v.size() - 1) { cout << " "; } } } //vectorの中身を改行区切りで出力 template<typename T> void print2(vector<T> v) { for (auto x : v) { cout << x << endl; } } //二次元配列を出力 template<typename T> void printvv(vector<vector<T>> vv) { for (vector<T> v : vv) { print1(v); cout << endl; } } //vectorを降順にソート template<typename T> void rsort(vector<T> &v) { sort(v.begin(), v.end()); reverse(v.begin(), v.end()); } //昇順priority_queueを召喚 template<typename T> struct rpriority_queue { priority_queue<T, vector<T>, greater<T>> pq; void push(T x) { pq.push(x); } void pop() { pq.pop(); } T top() { return pq.top(); } size_t size() { return pq.size(); } bool empty() { return pq.empty(); } }; int main() { ll N, M, W; cin >> N >> M >> W; vector<ll> X(N); rep(i, N) { cin >> X[i]; } vector<vector<ll>> Y(M, vector<ll>(2)); rep(i, M) { cin >> Y[i][0]; } rep(i, M) { cin >> Y[i][1]; } rsort(X); vector<ll> sum(N + 1); sum[0] = 0; rep(i, N) { sum[i + 1] = sum[i] + X[i]; } ll ans = 0; for (int i = 0; i < (1 << M); i++) { bitset<20> b = i; ll w = 0, v = 0; rep(j, M) { if (b[j]) { w += Y[j][0]; v += Y[j][1]; } } if (w <= W) { v += sum[min(W - w, N)]; ans = max(ans, v); } } cout << ans << endl; }