結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー ShibuyapShibuyap
提出日時 2020-08-03 05:57:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 1,280 bytes
コンパイル時間 2,068 ms
コンパイル使用メモリ 205,456 KB
実行使用メモリ 198,976 KB
最終ジャッジ日時 2023-09-29 13:19:09
合計ジャッジ時間 9,042 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 6 ms
7,752 KB
testcase_10 AC 4 ms
5,888 KB
testcase_11 AC 4 ms
5,832 KB
testcase_12 AC 30 ms
41,768 KB
testcase_13 AC 100 ms
139,492 KB
testcase_14 AC 18 ms
25,424 KB
testcase_15 AC 17 ms
27,084 KB
testcase_16 AC 26 ms
39,104 KB
testcase_17 AC 31 ms
47,316 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 4 ms
5,784 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 3 ms
4,708 KB
testcase_24 AC 148 ms
198,764 KB
testcase_25 AC 140 ms
198,700 KB
testcase_26 AC 141 ms
198,708 KB
testcase_27 AC 151 ms
198,716 KB
testcase_28 AC 125 ms
198,676 KB
testcase_29 AC 125 ms
198,756 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 3 ms
4,376 KB
testcase_33 AC 4 ms
4,956 KB
testcase_34 AC 5 ms
7,148 KB
testcase_35 AC 138 ms
198,676 KB
testcase_36 AC 138 ms
198,784 KB
testcase_37 AC 139 ms
198,700 KB
testcase_38 AC 138 ms
198,704 KB
testcase_39 AC 140 ms
198,732 KB
testcase_40 AC 135 ms
198,696 KB
testcase_41 AC 137 ms
198,672 KB
testcase_42 AC 137 ms
198,848 KB
testcase_43 AC 136 ms
198,848 KB
testcase_44 AC 138 ms
198,940 KB
testcase_45 AC 137 ms
198,736 KB
testcase_46 AC 125 ms
198,732 KB
testcase_47 AC 125 ms
198,732 KB
testcase_48 AC 126 ms
198,684 KB
testcase_49 AC 125 ms
198,768 KB
testcase_50 AC 124 ms
198,716 KB
testcase_51 AC 125 ms
198,680 KB
testcase_52 AC 112 ms
160,492 KB
testcase_53 AC 139 ms
198,676 KB
testcase_54 AC 110 ms
198,976 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n, k;
    cin >> n >> k;
    vector<P> v(n);
    rep(i,n) cin >> v[i].first >> v[i].second;
    sort(v.begin(), v.end(), greater<P>());
    int a[n], b[n];
    rep(i,n){
        a[i] = v[i].first;
        b[i] = v[i].second;
    }
    

    int dp[n][k+1][2];
    rep(i,n)rep(j,k+1)rep(l,2)dp[i][j][l] = 0;

    rep(i,n){
        if(i == 0){
            dp[0][a[i]][1] = b[i];
        }else{
            rep(j,k+1){
                dp[i][j][0] = dp[i-1][j][0];
                if(dp[i-1][j][1] != 0){
                    dp[i][j][0] = max(dp[i][j][0], dp[i-1][j][1] + b[i]);
                }
            }
            rep(j,k+1){
                dp[i][j][1] = dp[i-1][j][1];
                if(j-a[i] >= 0){
                    dp[i][j][1] = max(dp[i][j][1], dp[i-1][j-a[i]][0] + b[i]);
                }
            }
        }
    }

    int ans = 0;
    rep(j,k+1)rep(l,2) ans = max(ans, dp[n-1][j][l]);
    cout << ans << endl;
    return 0;
}
 
 
0