結果
| 問題 |
No.951 【本日限定】1枚頼むともう1枚無料!
|
| コンテスト | |
| ユーザー |
koyopro
|
| 提出日時 | 2019-12-30 18:25:22 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 508 ms / 2,000 ms |
| コード長 | 1,817 bytes |
| コンパイル時間 | 1,673 ms |
| コンパイル使用メモリ | 164,756 KB |
| 実行使用メモリ | 394,240 KB |
| 最終ジャッジ日時 | 2024-11-14 06:09:03 |
| 合計ジャッジ時間 | 16,123 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 52 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)
#define MAX LONG_LONG_MAX
int dxy[] = {0, 1, 0, -1, 0};
/*================================*/
int N, K;
struct P {
int score;
int price;
};
signed main()
{
#if DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
cin >> N >> K;
vector<P> LIST(N);
REP(i, N) {
cin >> LIST[i].price >> LIST[i].score;
}
sort(ALL(LIST), [](const P a, const P b) {return a.price > b.price || (a.price == b.price && a.score > b.score); });
int DP[N][K+1][2];
REP(i, N) REP(j, K+1) REP(k, 2) DP[i][j][k] = -1;
DP[0][K][0] = 0;
P p = LIST[0];
if (K >= p.price) {
DP[0][K - p.price][1] = p.score;
}
FOR(i, 1, N) REP(j, K+1) REP(k, 2) {
P p = LIST[i];
if (DP[i-1][j][k] > -1) {
if (j >= p.price) DP[i][j - p.price][1] = max(DP[i][j - p.price][1], DP[i-1][j][k] + p.score); // 買った場合
if (k == 1) DP[i][j][0] = max(DP[i][j][0], DP[i-1][j][k] + p.score); // 特典を利用した場合
DP[i][j][k] = max(DP[i][j][k], DP[i-1][j][k]); // 買わなかった場合
}
}
int ans = 0;
REP(i, N) REP(j, K+1) REP(k, 2) {
ans = max(ans, DP[i][j][k]);
}
cout << ans << endl;
return 0;
}
koyopro