結果
問題 | No.2329 Nafmo、イカサマをする |
ユーザー |
![]() |
提出日時 | 2023-05-28 15:14:40 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 207 ms / 2,000 ms |
コード長 | 1,212 bytes |
コンパイル時間 | 926 ms |
コンパイル使用メモリ | 84,060 KB |
最終ジャッジ日時 | 2025-02-13 12:50:15 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <iostream>#include <vector>#include <set>template<class T> bool chmax(T &a, const T &x) { return (x > a ? a = x, true : false); }int main() {constexpr long long inf = 1e18;long long N, M, K;std::cin >> N >> M >> K;auto A = std::vector(N, 0LL);for (int i = 0; i < N; ++i)std::cin >> A[i];A.push_back(0);auto pick1 = std::set(A.begin(), A.end());std::set<long long> pick2, pick3;for (const auto x : pick1)for (const auto a : A)pick2.insert(x + a);for (const auto x : pick2)for (const auto a : A)pick3.insert(x + a);pick1.insert(inf);pick2.insert(inf);pick3.insert(inf);auto f = [&](int k) {switch (k) {case 1:return &pick1;case 2:return &pick2;case 3:return &pick3;default:std::terminate();}};auto answer = 0LL;if (K <= 3)answer = *prev(f(K)->upper_bound(M));elsefor (auto i = pick3.begin(); i != pick3.upper_bound(M); ++i)chmax(answer, *i + *prev(f(K - 3)->upper_bound(M - *i)));std::cout << answer << "\n";}