結果

問題 No.1947 質より種類数
ユーザー karinohitokarinohito
提出日時 2022-05-21 00:51:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 509 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 3,983 ms
コンパイル使用メモリ 208,252 KB
実行使用メモリ 394,604 KB
最終ジャッジ日時 2023-10-20 15:21:21
合計ジャッジ時間 8,090 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 4 ms
5,476 KB
testcase_05 AC 3 ms
4,684 KB
testcase_06 AC 4 ms
4,948 KB
testcase_07 AC 4 ms
5,212 KB
testcase_08 AC 4 ms
5,476 KB
testcase_09 AC 12 ms
12,076 KB
testcase_10 AC 9 ms
9,436 KB
testcase_11 AC 25 ms
23,164 KB
testcase_12 AC 18 ms
16,828 KB
testcase_13 AC 8 ms
8,380 KB
testcase_14 AC 126 ms
112,660 KB
testcase_15 AC 66 ms
58,804 KB
testcase_16 AC 180 ms
162,820 KB
testcase_17 AC 231 ms
210,340 KB
testcase_18 AC 509 ms
373,732 KB
testcase_19 AC 365 ms
326,492 KB
testcase_20 AC 278 ms
245,708 KB
testcase_21 AC 326 ms
289,532 KB
testcase_22 AC 20 ms
19,196 KB
testcase_23 AC 150 ms
131,132 KB
testcase_24 AC 6 ms
6,260 KB
testcase_25 AC 4 ms
5,468 KB
testcase_26 AC 3 ms
4,412 KB
testcase_27 AC 4 ms
4,940 KB
testcase_28 AC 5 ms
5,468 KB
testcase_29 AC 452 ms
394,600 KB
testcase_30 AC 445 ms
394,604 KB
testcase_31 AC 2 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
testcase_33 AC 2 ms
4,348 KB
testcase_34 AC 368 ms
394,604 KB
testcase_35 AC 366 ms
394,604 KB
testcase_36 AC 446 ms
394,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll =vector<vll>;
#define all(A) A.begin(),A.end()
#define rep(i, n) for (ll i = 0; i < (ll) (n); i++)


bool chmax(ll& p, ll q) {
    if (p < q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}

bool chmin(ll& p, ll q) {
    if (p > q) {
        p = q;
        return 1;
    }
    else {
        return 0;
    }
}


int main() {
    
    ll N,V,C;cin>>N>>V>>C;
    
    vll A(N),B(N);
    rep(i,N)cin>>A[i]>>B[i];

    vvll DP(N+1,vll(V+1,-1e18));
    DP[0][0]=0;
    rep(i,N){
        rep(v,V+1){
            chmax(DP[i+1][v],DP[i][v]);
            if(v+A[i]<=V){
                chmax(DP[i+1][v+A[i]],DP[i][v]+B[i]+C);
            }
        }
    }
    vvll DP2(N+1,vll(V+1,-1e18));
    DP2[0]=DP[N];
    rep(i,N){
        rep(v,V+1){
            chmax(DP2[i+1][v],DP2[i][v]);
            if(v+A[i]<=V){
                chmax(DP2[i+1][v+A[i]],DP2[i][v]+B[i]);
                chmax(DP2[i+1][v+A[i]],DP2[i+1][v]+B[i]);
            }
        }
    }
    ll an=0;
    rep(v,V+1)chmax(an,DP2[N][v]);
    cout<<an<<endl;

    
}
0