結果
問題 | No.2329 Nafmo、イカサマをする |
ユーザー |
|
提出日時 | 2023-05-28 16:15:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 2,105 bytes |
コンパイル時間 | 2,081 ms |
コンパイル使用メモリ | 202,840 KB |
最終ジャッジ日時 | 2025-02-13 15:13:44 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }int main() {ll n, m, k;cin >> n >> m >> k;vector<ll> a1(n + 1);for (ll i = 0; i < n; i++) {cin >> a1[i];}n++;sort(a1.begin(), a1.end());vector<ll> a2;for (ll i = 0; i < n; i++) {for (ll id = 0; id < n; id++) {a2.push_back(a1[i] + a1[id]);}}sort(a2.begin(), a2.end());vector<ll> a3;for (ll i = 0; i < n; i++) {for (ll id = 0; id < n; id++) {for (ll idx = 0; idx < n; idx++) {a3.push_back(a1[i] + a1[id] + a1[idx]);}}}sort(a3.begin(), a3.end());if (k == 1) {cout << *prev(upper_bound(a1.begin(), a1.end(), m)) << endl;}else if (k == 2) {cout << *prev(upper_bound(a2.begin(), a2.end(), m)) << endl;}else if (k == 3) {cout << *prev(upper_bound(a3.begin(), a3.end(), m)) << endl;}else if (k == 4) {ll ans = 0;for (ll i = 0; i < a2.size(); i++) {if (a2[i] > m) {continue;}auto key = m - a2[i];auto it = prev(upper_bound(a2.begin(), a2.end(), key));chmax(ans, a2[i] + *it);}cout << ans << endl;}else if (k == 5) {ll ans = 0;for (ll i = 0; i < a2.size(); i++) {if (a2[i] > m) {continue;}auto key = m - a2[i];auto it = prev(upper_bound(a3.begin(), a3.end(), key));chmax(ans, a2[i] + *it);}cout << ans << endl;}else {ll ans = 0;for (ll i = 0; i < a3.size(); i++) {if (a3[i] > m) {continue;}auto key = m - a3[i];auto it = prev(upper_bound(a3.begin(), a3.end(), key));chmax(ans, a3[i] + *it);}cout << ans << endl;}return 0;}