結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー nanophoto12nanophoto12
提出日時 2020-01-01 19:16:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 113 ms / 2,000 ms
コード長 1,555 bytes
コンパイル時間 1,423 ms
コンパイル使用メモリ 133,960 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-14 16:59:43
合計ジャッジ時間 6,078 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 24 ms
4,376 KB
testcase_13 AC 79 ms
4,380 KB
testcase_14 AC 15 ms
4,376 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 19 ms
4,376 KB
testcase_17 AC 24 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 4 ms
4,380 KB
testcase_22 AC 3 ms
4,380 KB
testcase_23 AC 3 ms
4,376 KB
testcase_24 AC 113 ms
4,376 KB
testcase_25 AC 112 ms
4,376 KB
testcase_26 AC 108 ms
4,380 KB
testcase_27 AC 109 ms
4,380 KB
testcase_28 AC 92 ms
4,380 KB
testcase_29 AC 93 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 4 ms
4,376 KB
testcase_34 AC 5 ms
4,376 KB
testcase_35 AC 111 ms
4,376 KB
testcase_36 AC 112 ms
4,376 KB
testcase_37 AC 112 ms
4,376 KB
testcase_38 AC 112 ms
4,376 KB
testcase_39 AC 112 ms
4,380 KB
testcase_40 AC 109 ms
4,380 KB
testcase_41 AC 109 ms
4,380 KB
testcase_42 AC 109 ms
4,380 KB
testcase_43 AC 109 ms
4,376 KB
testcase_44 AC 109 ms
4,376 KB
testcase_45 AC 109 ms
4,380 KB
testcase_46 AC 92 ms
4,380 KB
testcase_47 AC 93 ms
4,380 KB
testcase_48 AC 93 ms
4,376 KB
testcase_49 AC 94 ms
4,384 KB
testcase_50 AC 93 ms
4,376 KB
testcase_51 AC 92 ms
4,376 KB
testcase_52 AC 91 ms
4,376 KB
testcase_53 AC 113 ms
4,380 KB
testcase_54 AC 73 ms
4,380 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[0][j][0]);
        cmax(m, dp[0][j][1]);
    }
    cout << m << endl;
    return 0;
}

0