結果

問題 No.1522 Unfairness
ユーザー shiomusubi496shiomusubi496
提出日時 2021-05-28 21:24:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 898 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 2,307 ms
コンパイル使用メモリ 208,640 KB
実行使用メモリ 495,800 KB
最終ジャッジ日時 2023-08-12 07:27:08
合計ジャッジ時間 10,465 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 219 ms
131,680 KB
testcase_04 AC 55 ms
36,828 KB
testcase_05 AC 21 ms
15,204 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 327 ms
192,852 KB
testcase_08 AC 314 ms
190,432 KB
testcase_09 AC 9 ms
8,144 KB
testcase_10 AC 91 ms
55,572 KB
testcase_11 AC 41 ms
28,404 KB
testcase_12 AC 146 ms
88,652 KB
testcase_13 AC 449 ms
272,064 KB
testcase_14 AC 41 ms
25,752 KB
testcase_15 AC 898 ms
495,660 KB
testcase_16 AC 854 ms
495,676 KB
testcase_17 AC 856 ms
495,732 KB
testcase_18 AC 857 ms
495,800 KB
testcase_19 AC 848 ms
495,608 KB
testcase_20 AC 848 ms
495,676 KB
testcase_21 AC 1 ms
4,384 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,384 KB
testcase_24 AC 5 ms
5,272 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 4 ms
5,168 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 6 ms
5,808 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