結果

問題 No.2329 Nafmo、イカサマをする
ユーザー kobaryo222kobaryo222
提出日時 2023-05-28 15:45:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 2,956 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 207,872 KB
実行使用メモリ 13,304 KB
最終ジャッジ日時 2023-08-27 12:52:37
合計ジャッジ時間 4,732 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,384 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 20 ms
5,208 KB
testcase_20 AC 8 ms
4,380 KB
testcase_21 AC 24 ms
5,176 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 24 ms
5,096 KB
testcase_24 AC 9 ms
4,380 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 8 ms
4,380 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 29 ms
7,496 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 6 ms
4,380 KB
testcase_34 AC 9 ms
4,376 KB
testcase_35 AC 3 ms
4,380 KB
testcase_36 AC 63 ms
8,568 KB
testcase_37 AC 16 ms
5,100 KB
testcase_38 AC 91 ms
12,112 KB
testcase_39 AC 112 ms
12,304 KB
testcase_40 AC 99 ms
11,280 KB
testcase_41 AC 134 ms
13,304 KB
testcase_42 AC 99 ms
12,680 KB
権限があれば一括ダウンロードができます

ソースコード

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