結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー nanophoto12nanophoto12
提出日時 2020-01-01 19:12:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,555 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 133,580 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 05:01:42
合計ジャッジ時間 5,930 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 25 ms
5,376 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 113 ms
5,376 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 3 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 WA -
testcase_35 AC 113 ms
5,376 KB
testcase_36 AC 112 ms
5,376 KB
testcase_37 AC 113 ms
5,376 KB
testcase_38 AC 113 ms
5,376 KB
testcase_39 AC 113 ms
5,376 KB
testcase_40 AC 112 ms
5,376 KB
testcase_41 AC 111 ms
5,376 KB
testcase_42 AC 110 ms
5,376 KB
testcase_43 AC 112 ms
5,376 KB
testcase_44 AC 108 ms
5,376 KB
testcase_45 AC 111 ms
5,376 KB
testcase_46 AC 94 ms
5,376 KB
testcase_47 AC 94 ms
5,376 KB
testcase_48 AC 95 ms
5,376 KB
testcase_49 WA -
testcase_50 AC 94 ms
5,376 KB
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 AC 74 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <unordered_map>
#include <sstream>
#include <stack>

using namespace std;

typedef long long int ll;
typedef pair<char,char> pcc;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> t3;

#define rep(i,a) for(ll i = 0;i < a;i++)

template <class T>
void cmax(T& a, const T b){a=max(a,b);}

const ll mod = 1e9+7;

int main(void) {
    ll n,k;
    cin >> n >> k;
    vector<P> vs(n);
    rep(i,n){
        cin >> vs[i].first >> vs[i].second;
    }
    sort(vs.begin(),vs.end(),[&](P a, P b){
        if(a.first == b.first){
            return a.second > b.second;
        }
        return a.first > b.first;
    });
    vector<vector<vector<ll>>> dp(2, vector<vector<ll>>(k+10, vector<ll>(2,0)));
    rep(i,n){
        auto p = vs[i].first;
        auto d = vs[i].second;
        for(int j = 0;j <= k;j++){
            cmax(dp[1][j][0],dp[0][j][0]);
            cmax(dp[1][j][1],dp[0][j][1]);
            if(dp[0][j][1] != 0){
                cmax(dp[1][j][0],dp[0][j][1] + d);
            }
        }
        for(int j = 0;j+p <= k;j++){
            cmax(dp[1][j+p][1], dp[0][j][0] + d);
        }
        swap(dp[0], dp[1]);
    }
    ll m = 0;
    rep(j,k+1){
        cmax(m, dp[1][j][0]);
        cmax(m, dp[1][j][1]);
    }
    cout << m << endl;
    return 0;
}

0