結果

問題 No.1522 Unfairness
ユーザー snow39snow39
提出日時 2021-06-02 23:33:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 75 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 1,097 ms
コンパイル使用メモリ 115,584 KB
実行使用メモリ 73,856 KB
最終ジャッジ日時 2024-04-29 21:58:57
合計ジャッジ時間 2,664 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 21 ms
21,632 KB
testcase_04 AC 6 ms
7,936 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 30 ms
30,464 KB
testcase_08 AC 29 ms
30,080 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 9 ms
10,880 KB
testcase_11 AC 5 ms
6,784 KB
testcase_12 AC 14 ms
15,488 KB
testcase_13 AC 41 ms
41,728 KB
testcase_14 AC 5 ms
6,656 KB
testcase_15 AC 74 ms
73,728 KB
testcase_16 AC 74 ms
73,728 KB
testcase_17 AC 74 ms
73,856 KB
testcase_18 AC 75 ms
73,728 KB
testcase_19 AC 73 ms
73,728 KB
testcase_20 AC 65 ms
73,728 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

#define mkp make_pair
#define mkt make_tuple
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
template <class T> void chmin(T &a, const T &b) {
    if (a > b) a = b;
}
template <class T> void chmax(T &a, const T &b) {
    if (a < b) a = b;
}

const ll INF = 1e18;

void solve() {
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    sort(all(A));
    reverse(all(A));

    vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, -INF));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= M; j++) {
            ll value = dp[i][j];
            if (value == -INF) continue;
            chmax(dp[i + 1][j], value);
            if (i + 2 <= N && j + A[i] - A[i + 1] <= M)
                chmax(dp[i + 2][j + A[i] - A[i + 1]], value + A[i]);
        }
    }

    ll ans = *max_element(all(dp[N]));
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0