結果

問題 No.2329 Nafmo、イカサマをする
ユーザー KKT89
提出日時 2023-05-28 14:15:59
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,698 bytes
コンパイル時間 2,641 ms
コンパイル使用メモリ 220,876 KB
最終ジャッジ日時 2025-02-13 11:08:09
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m,k; cin >> n >> m >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    n++; a.push_back(0);
    vector<ll> v,vv;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            for (int l = 0; l < n; ++l) {
                {
                    ll cost = 0;
                    cost += (k/2 >= 1 ? a[i] : 0);
                    cost += (k/2 >= 2 ? a[j] : 0);
                    cost += (k/2 >= 3 ? a[l] : 0);
                    v.push_back(cost);
                }
                {
                    ll cost = 0;
                    cost += (k-k/2 >= 1 ? a[i] : 0);
                    cost += (k-k/2 >= 2 ? a[j] : 0);
                    cost += (k-k/2 >= 3 ? a[l] : 0);
                    vv.push_back(cost);
                }
            }
        }
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    sort(vv.begin(), vv.end());
    vv.erase(unique(vv.begin(), vv.end()), vv.end());

    ll res = 0;
    for (auto p : v) {
        if (p > m) break;
        auto it = upper_bound(vv.begin(), vv.end(), m-p);
        it--;
        res = max(res, p+*it);
    }
    cout << res << endl;
}
0