結果

問題 No.1522 Unfairness
ユーザー shiomusubi496shiomusubi496
提出日時 2021-05-28 21:24:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 854 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 2,388 ms
コンパイル使用メモリ 211,216 KB
実行使用メモリ 496,000 KB
最終ジャッジ日時 2024-04-29 21:55:30
合計ジャッジ時間 9,912 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 225 ms
131,840 KB
testcase_04 AC 54 ms
36,864 KB
testcase_05 AC 21 ms
15,360 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 336 ms
193,024 KB
testcase_08 AC 327 ms
190,720 KB
testcase_09 AC 10 ms
8,064 KB
testcase_10 AC 94 ms
55,808 KB
testcase_11 AC 41 ms
28,544 KB
testcase_12 AC 149 ms
88,704 KB
testcase_13 AC 463 ms
272,128 KB
testcase_14 AC 40 ms
25,984 KB
testcase_15 AC 854 ms
496,000 KB
testcase_16 AC 848 ms
495,872 KB
testcase_17 AC 848 ms
495,872 KB
testcase_18 AC 850 ms
495,872 KB
testcase_19 AC 847 ms
495,872 KB
testcase_20 AC 844 ms
495,872 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 4 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 6 ms
5,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define int long long
using namespace std;
constexpr int INF=1e18;
void chmax(int&a,int b){if(a<b)a=b;}
signed main(){
    int N,M; cin>>N>>M;
    vector<int> A(N);
    for(int i=0;i<N;i++) cin>>A[i];
    sort(A.begin(),A.end());
    vector<vector<vector<int>>>dp(N,vector<vector<int>>(M+1,vector<int>(2,-INF)));
    dp[0][0][0]=0;
    for(int i=1;i<N;i++){
        for(int j=0;j<=M;j++){
            chmax(dp[i][j][0],dp[i-1][j][0]);
            chmax(dp[i][j][0],dp[i-1][j][1]);
        }
        for(int j=0;j<=M;j++){
            if(j+abs(A[i]-A[i-1])<=M){
                chmax(dp[i][j+abs(A[i]-A[i-1])][1],dp[i-1][j][0]+A[i]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<=M;i++){
        chmax(ans,dp[N-1][i][0]);
        chmax(ans,dp[N-1][i][1]);
    }
    cout<<ans<<endl;
}
0