結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
tamaron
|
| 提出日時 | 2019-12-23 18:41:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 330 ms / 2,000 ms |
| コード長 | 927 bytes |
| コンパイル時間 | 1,974 ms |
| コンパイル使用メモリ | 180,788 KB |
| 実行使用メモリ | 296,960 KB |
| 最終ジャッジ日時 | 2024-09-17 21:17:49 |
| 合計ジャッジ時間 | 12,118 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef int 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;
}
tamaron