結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1LL << 60)
#define all(v) (v).begin(), (v).end()

template <class T>
void chmin(T &a, T b) {
    if (a > b) a = b;
}

template <class T>
void chmax(T &a, T b) {
    if (a < b) a = b;
}

template <int mod>
struct ModInt {
    int x;

    ModInt() : x(0) {}

    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt &operator+=(const ModInt &p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator-=(const ModInt &p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }

    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt &p) const { return x == p.x; }

    bool operator!=(const ModInt &p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const {
        ModInt ret(1), mul(x);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a) {
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() { return mod; }
};

using mint = ModInt<1000000007>;

int main() {
    ll N, M, K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    rep(i, N) { cin >> A[i]; }
    vector<vector<ll>> s(3);
    ll ans = 0;
    rep(i, N) {
        s[0].push_back(A[i]);
        if (K >= 1 && A[i] <= M) chmax(ans, A[i]);
        rep(j, N) {
            s[1].push_back(A[i] + A[j]);
            rep(k, N) { s[2].push_back(A[i] + A[j] + A[k]); }
        }
    }
    rep(i, 3) { sort(all(s[i])); }
    rep(i, 3) {
        rep(j, 3) {
            if (i + j + 2 > K) continue;
            rep(k, s[i].size()) {
                ll goal = M - s[i][k] + 1;
                auto itr = lower_bound(all(s[j]), goal);
                if (itr == s[j].begin()) continue;
                itr--;
                chmax(ans, s[i][k] + *itr);
            }
        }
    }
    cout << ans << endl;
}
0