結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー tamarontamaron
提出日時 2019-12-23 18:41:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 316 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 3,429 ms
コンパイル使用メモリ 179,776 KB
実行使用メモリ 296,936 KB
最終ジャッジ日時 2023-10-18 00:13:58
合計ジャッジ時間 12,133 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 8 ms
9,968 KB
testcase_10 AC 5 ms
7,064 KB
testcase_11 AC 6 ms
7,328 KB
testcase_12 AC 65 ms
61,184 KB
testcase_13 AC 223 ms
208,232 KB
testcase_14 AC 38 ms
36,632 KB
testcase_15 AC 38 ms
39,272 KB
testcase_16 AC 55 ms
57,224 KB
testcase_17 AC 69 ms
69,896 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 6 ms
7,064 KB
testcase_22 AC 3 ms
4,688 KB
testcase_23 AC 4 ms
5,480 KB
testcase_24 AC 312 ms
296,936 KB
testcase_25 AC 316 ms
296,936 KB
testcase_26 AC 314 ms
296,936 KB
testcase_27 AC 313 ms
296,936 KB
testcase_28 AC 285 ms
296,936 KB
testcase_29 AC 287 ms
296,936 KB
testcase_30 AC 2 ms
4,348 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 4 ms
4,952 KB
testcase_33 AC 5 ms
6,008 KB
testcase_34 AC 8 ms
9,176 KB
testcase_35 AC 307 ms
296,936 KB
testcase_36 AC 311 ms
296,936 KB
testcase_37 AC 309 ms
296,936 KB
testcase_38 AC 314 ms
296,936 KB
testcase_39 AC 315 ms
296,936 KB
testcase_40 AC 312 ms
296,936 KB
testcase_41 AC 307 ms
296,936 KB
testcase_42 AC 312 ms
296,936 KB
testcase_43 AC 312 ms
296,936 KB
testcase_44 AC 315 ms
296,936 KB
testcase_45 AC 313 ms
296,936 KB
testcase_46 AC 290 ms
296,936 KB
testcase_47 AC 286 ms
296,936 KB
testcase_48 AC 285 ms
296,936 KB
testcase_49 AC 286 ms
296,936 KB
testcase_50 AC 287 ms
296,936 KB
testcase_51 AC 286 ms
296,936 KB
testcase_52 AC 255 ms
239,648 KB
testcase_53 AC 316 ms
296,936 KB
testcase_54 AC 265 ms
296,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int ll;
const long long INF = 1e18;

void chmax(ll *a,ll b){
    if (*a<b) *a=b;
    return;
}

int main(){
    ll N,K;
    cin>>N>>K;
    // first:=cost second:=value
    vector<pair<ll,ll>> d(N); 
    rep(i,N) cin>>d[i].first>>d[i].second;
    sort(d.begin(),d.end());
    reverse(d.begin(),d.end());
    vector<vector<vector<ll>>> dp(2,vector<vector<ll>>(N+1,vector<ll>(K+1,0)));
    rep(i,N)rep(j,K+1){
        chmax(&dp[0][i+1][j],dp[0][i][j]);
        if (j+d[i].first<=K) chmax(&dp[1][i+1][j+d[i].first],dp[0][i][j]+d[i].second);
        if (dp[1][i][j]!=0){
            chmax(&dp[1][i+1][j],dp[1][i][j]);
            chmax(&dp[0][i+1][j],dp[1][i][j]+d[i].second);
        }
    }
    ll res=0;
    rep(i,K+1){
        chmax(&res,dp[0][N][i]);
        chmax(&res,dp[1][N][i]);
    }
    cout<<res<<endl;
    return 0;
}
0