結果

問題 No.1522 Unfairness
ユーザー aspiaspi
提出日時 2021-05-04 10:30:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 976 bytes
コンパイル時間 2,061 ms
コンパイル使用メモリ 209,880 KB
実行使用メモリ 38,528 KB
最終ジャッジ日時 2024-04-29 21:53:01
合計ジャッジ時間 3,259 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 12 ms
12,416 KB
testcase_04 AC 4 ms
5,760 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 17 ms
17,024 KB
testcase_08 AC 17 ms
16,768 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 6 ms
7,296 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 8 ms
9,344 KB
testcase_13 AC 26 ms
22,528 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 48 ms
38,528 KB
testcase_16 AC 43 ms
38,528 KB
testcase_17 AC 44 ms
38,528 KB
testcase_18 AC 48 ms
38,528 KB
testcase_19 AC 48 ms
38,528 KB
testcase_20 AC 43 ms
38,528 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 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 1 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 <bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T& xx, T yy) { if (xx < yy) { xx = yy; return true; }return false; }

int main() {
    int N, M, ans = 0;
    cin >> N >> M;
    vector<int>numbers(N);
    vector<pair<int, int>>pairs(N - 1);
    vector<vector<int>>dp(N + 1, vector<int>(M + 1, 0));
    dp[0][0] = 0;
    for (int i = 0; i < N; i++)cin >> numbers[i];
    sort(numbers.begin(), numbers.end());
    reverse(numbers.begin(), numbers.end());
    for (int i = 0; i < N - 1; i++) {
        pairs[i].first = numbers[i] - numbers[i + 1];
        pairs[i].second = numbers[i];
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M + 1; j++) {
            if (i < N - 1 && j + pairs[i].first <= M) {
                dp[i + 2][j + pairs[i].first] = dp[i][j] + pairs[i].second;
            }
            chmax(dp[i + 1][j], dp[i][j]);
        }
    }
    for(int i=0; i < M + 1; i++) chmax(ans, dp[N][i]);
    cout << ans << endl;
}
0