結果
問題 | No.951 【本日限定】1枚頼むともう1枚無料! |
ユーザー |
![]() |
提出日時 | 2019-12-18 23:18:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 140 ms / 2,000 ms |
コード長 | 1,477 bytes |
コンパイル時間 | 1,479 ms |
コンパイル使用メモリ | 174,404 KB |
実行使用メモリ | 199,040 KB |
最終ジャッジ日時 | 2024-07-06 23:03:03 |
合計ジャッジ時間 | 7,160 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 52 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> l_l; typedef pair<int, int> i_i; template<class T> inline bool chmax(T &a, T b) { if(a < b) { a = b; return true; } return false; } template<class T> inline bool chmin(T &a, T b) { if(a > b) { a = b; return true; } return false; } #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) //const ll mod = 1000000007; int N, K; int dp[5001][5001][2]; vector<i_i> INPUT; int main() { //cout.precision(10); cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; INPUT.resize(N); for(int i = 0; i < N; i++) { cin >> INPUT[i].first >> INPUT[i].second; } sort(INPUT.begin(), INPUT.end(), greater<i_i>()); for(int i = 0; i <= 5000; i++) { for(int j = 0; j <= 5000; j++) { dp[i][j][1] = -1e9; } } for(int i = 0; i < N; i++) { int P = INPUT[i].first; int V = INPUT[i].second; for(int j = 0; j <= K; j++) { chmax(dp[i+1][j][0], dp[i][j][0]); chmax(dp[i+1][j][1], dp[i][j][1]); chmax(dp[i+1][j][0], dp[i][j][1] + V); if(j + P <= K) { chmax(dp[i+1][j+P][1], dp[i][j][0] + V); } } } int ans = 0; for(int i = 0; i <= K; i++) { chmax(ans, dp[N][i][0]); chmax(ans, dp[N][i][1]); } cout << ans << endl; return 0; }