結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー ngtkana
提出日時 2020-04-13 23:01:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 839 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 203,452 KB
最終ジャッジ日時 2025-01-09 18:17:12
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 52
権限があれば一括ダウンロードができます

ソースコード

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