結果
問題 | No.2329 Nafmo、イカサマをする |
ユーザー |
|
提出日時 | 2023-05-28 15:40:35 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 124 ms / 2,000 ms |
コード長 | 994 bytes |
コンパイル時間 | 2,305 ms |
コンパイル使用メモリ | 179,660 KB |
実行使用メモリ | 11,580 KB |
最終ジャッジ日時 | 2024-12-27 08:00:09 |
合計ジャッジ時間 | 4,743 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){ios::sync_with_stdio(false);cin.tie(0);ll n, m, k;cin >> n >> m >> k;vector<ll> a(n);for(auto &&v : a) cin >> v;vector<vector<ll>> dp(4);dp[0].push_back(0);dp[1] = a;for(int i = 1; i < 3; i++){for(int j = 0; j < dp[i].size(); j++){for(int k = 0; k < n; k++){dp[i + 1].emplace_back(dp[i][j] + a[k]);}}}for(int i = 0; i < 4; i++){sort(dp[i].begin(), dp[i].end());}vector<pair<int,int>> b = {{1, 0}, {2, 0}, {3, 0}, {1, 3}, {2, 3}, {3, 3}};ll ans = 0;for(int i = 0; i < k; i++){int s, t;tie(s, t) = b[i];for(int j = 0; j < dp[s].size(); j++){int k = upper_bound(dp[t].begin(), dp[t].end(), m - dp[s][j]) - dp[t].begin() - 1;if(k >= 0) ans = max(ans, dp[s][j] + dp[t][k]);}}cout << ans << '\n';}