結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
tko919
|
| 提出日時 | 2019-12-14 16:28:16 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 2,000 ms |
| コード長 | 1,042 bytes |
| コンパイル時間 | 1,784 ms |
| コンパイル使用メモリ | 173,080 KB |
| 実行使用メモリ | 199,524 KB |
| 最終ジャッジ日時 | 2024-06-28 03:12:55 |
| 合計ジャッジ時間 | 6,403 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end
typedef pair<int,int> P;
int dp[5010][5010][2]={}; //idx,sum,isfree
int main(){
int n,k; scanf("%d%d",&n,&k);
vector<P> p(n);
rep(i,0,n)scanf("%d%d",&p[i].first,&p[i].second);
sort(ALL(p));
rep(i,0,n){
rep(l,0,k+1)dp[i+1][l][0]=dp[i][l][0],dp[i+1][l][1]=dp[i][l][1];
rrep(l,k,-1){
chmax(dp[i+1][l][0],dp[i][l][1]+p[i].second);
chmax(dp[i+1][min(5005,l+p[i].first)][1],dp[i][l][0]+p[i].second);
}
}
int ans=0;
rep(i,0,k+1)chmax(ans,dp[n][i][1]);
printf("%d\n",ans);
return 0;
}
tko919