結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
iqueue02
|
| 提出日時 | 2019-12-15 13:47:19 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,463 ms / 2,000 ms |
| コード長 | 933 bytes |
| コンパイル時間 | 1,916 ms |
| コンパイル使用メモリ | 181,532 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 18:17:42 |
| 合計ジャッジ時間 | 40,960 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = 1e18;
int main(){
int n, K;
cin >> n >> K;
vector<P> A(n);
rep(i,n) {
int p, d;
cin >> p >> d;
A[i] = make_pair(p, d);
}
sort(A.begin(), A.end(), greater<P>());
vector<vector<ll>> dp(K+1, vector<ll>(2,-INF));
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
auto next = dp;
for (int j = 0; j <= K; j++) {
if (j + A[i].first <= K) next[j + A[i].first][1] = max(next[j + A[i].first][1], dp[j][0] + A[i].second);
next[j][0] = max(next[j][0], dp[j][1] + A[i].second);
next[j][0] = max(next[j][0], dp[j][0]);
next[j][1] = max(next[j][1], dp[j][1]);
}
dp = next;
}
ll res = 0;
for (int i = 0; i <= K; i++) res = max(res, max(dp[i][0], dp[i][1]));
cout << res << endl;
return 0;
}
iqueue02