結果
問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
ユーザー |
![]() |
提出日時 | 2019-12-23 18:25:01 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 933 bytes |
コンパイル時間 | 1,723 ms |
コンパイル使用メモリ | 181,252 KB |
実行使用メモリ | 590,208 KB |
最終ジャッジ日時 | 2024-09-17 20:50:55 |
合計ジャッジ時間 | 17,688 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 MLE * 25 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) typedef long long ll; const long long INF = 1e18; void chmax(ll *a,ll b){ if (*a<b) *a=b; return; } int main(){ ll N,K; cin>>N>>K; // first:=cost second:=value vector<pair<ll,ll>> d(N); rep(i,N) cin>>d[i].first>>d[i].second; sort(d.begin(),d.end()); reverse(d.begin(),d.end()); vector<vector<vector<ll>>> dp(2,vector<vector<ll>>(N+1,vector<ll>(K+1,0))); rep(i,N)rep(j,K+1){ chmax(&dp[0][i+1][j],dp[0][i][j]); if (j+d[i].first<=K) chmax(&dp[1][i+1][j+d[i].first],dp[0][i][j]+d[i].second); if (dp[1][i][j]!=0){ chmax(&dp[1][i+1][j],dp[1][i][j]); chmax(&dp[0][i+1][j],dp[1][i][j]+d[i].second); } } ll res=0; rep(i,K+1){ chmax(&res,dp[0][N][i]); chmax(&res,dp[1][N][i]); } cout<<res<<endl; return 0; }