結果
問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
ユーザー |
|
提出日時 | 2022-06-30 12:30:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 131 ms / 2,000 ms |
コード長 | 922 bytes |
コンパイル時間 | 826 ms |
コンパイル使用メモリ | 83,396 KB |
実行使用メモリ | 199,240 KB |
最終ジャッジ日時 | 2024-11-24 07:42:51 |
合計ジャッジ時間 | 5,145 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
#include<cstdio> #include<cstring> #include<iostream> #include<cmath> #include<ctime> #include<string> #include<algorithm> #include<vector> #include<queue> #include<stack> #include<map> using namespace std; typedef long long LL; const int MR=5000+5; int n,K,p[MR],d[MR]; int dp[MR][MR][2]; int main(){ cin>>n>>K; for(int i=1;i<=n;i++) cin>>p[i]>>d[i]; for(int i=1;i<=n;i++){ for(int j=i+1;j<=n;j++){ if(p[i]<p[j]){ swap(p[i],p[j]); swap(d[i],d[j]); } } } for(int j=0;j<=K;j++) dp[0][j][1]=-1e9; for(int i=1;i<=n;i++){ for(int j=0;j<=K;j++){ dp[i][j][0]=max(dp[i-1][j][0],dp[i-1][j][1]+d[i]); dp[i][j][1]=dp[i-1][j][1]; if(j>=p[i]) dp[i][j][1]=max(dp[i-1][j][1],dp[i-1][j-p[i]][0]+d[i]); } } int ans=max(dp[n][K][0],dp[n][K][1]); cout<<ans<<endl; return 0; }