結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー ngtkanangtkana
提出日時 2020-04-13 23:01:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 9,482 ms
コンパイル使用メモリ 210,108 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-26 04:11:37
合計ジャッジ時間 7,939 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 19 ms
4,348 KB
testcase_13 AC 57 ms
4,348 KB
testcase_14 AC 12 ms
4,348 KB
testcase_15 AC 9 ms
4,348 KB
testcase_16 AC 14 ms
4,348 KB
testcase_17 AC 18 ms
4,348 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 3 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 3 ms
4,348 KB
testcase_24 AC 82 ms
4,348 KB
testcase_25 AC 82 ms
4,348 KB
testcase_26 AC 77 ms
4,348 KB
testcase_27 AC 77 ms
4,348 KB
testcase_28 AC 65 ms
4,348 KB
testcase_29 AC 66 ms
4,348 KB
testcase_30 AC 2 ms
4,348 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 4 ms
4,348 KB
testcase_35 AC 71 ms
4,348 KB
testcase_36 AC 72 ms
4,348 KB
testcase_37 AC 70 ms
4,348 KB
testcase_38 AC 72 ms
4,348 KB
testcase_39 AC 73 ms
4,348 KB
testcase_40 AC 70 ms
4,348 KB
testcase_41 AC 72 ms
4,348 KB
testcase_42 AC 73 ms
4,348 KB
testcase_43 AC 74 ms
4,348 KB
testcase_44 AC 73 ms
4,348 KB
testcase_45 AC 73 ms
4,348 KB
testcase_46 AC 69 ms
4,348 KB
testcase_47 AC 67 ms
4,348 KB
testcase_48 AC 66 ms
4,348 KB
testcase_49 AC 66 ms
4,348 KB
testcase_50 AC 65 ms
4,348 KB
testcase_51 AC 65 ms
4,348 KB
testcase_52 AC 62 ms
4,348 KB
testcase_53 AC 77 ms
4,348 KB
testcase_54 AC 50 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
void cmx(lint&x,lint y){if(x<y)x=y;}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n,k;std::cin>>n>>k;
    std::vector<std::pair<lint,lint>>a(n);
    for(auto&&p:a)std::cin>>p.first>>p.second;
    std::sort(ALL(a),std::greater<>{});
    std::vector<std::array<lint,2>>dp(k+1,{0,-1});
    for(auto[p,d]:a){
        for(lint i=k;i>=0;i--){
            if(i+p<=k&&dp.at(i).at(0)!=-1)cmx(dp.at(i+p).at(1),dp.at(i).at(0)+d);
            if(dp.at(i).at(1)!=-1)cmx(dp.at(i).at(0),dp.at(i).at(1)+d);
        }
    }
    std::cout<<std::max(dp.at(k).at(0),dp.at(k).at(1))<<'\n';
}
0