結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
imoni_kawaii
|
| 提出日時 | 2020-06-13 12:08:16 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 289 ms / 2,000 ms |
| コード長 | 1,297 bytes |
| コンパイル時間 | 2,934 ms |
| コンパイル使用メモリ | 199,100 KB |
| 最終ジャッジ日時 | 2025-01-11 03:40:00 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using ll = long long; using ld = long double; using pll = pair<ll, ll>;
const int INF = 1<<30; const ll LINF = 1LL<<60; const ld PI = 3.1415926535897932;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }
int dp[5010][5010][2];
signed main() {
cin.tie(0); ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<pll> p(N);
rep(i, N) cin >> p[i].first >> p[i].second;
sort(p.begin(), p.end(), greater<pll>());
rep(i, 5010) rep(j, 5010) rep(k, 2) dp[i][j][k] = -INF;
rep(j, 5010) dp[0][j][0] = 0;
rep(i, N) rep(j, K+1) {
rep(k, 2) {
if(dp[i][j][k] == -INF) continue;
chmax(dp[i+1][j][k], dp[i][j][k]);
}
if(dp[i][j][0] != -INF && j+p[i].first <= K) chmax(dp[i+1][j+p[i].first][1], dp[i][j][0]+p[i].second);
if(dp[i][j][0] != -INF) chmax(dp[i+1][j][0], dp[i][j][1]+p[i].second);
}
int ans = max(dp[N][K][1], dp[N][K][0]);
cout << ans << '\n';
return 0;
}
imoni_kawaii