結果
| 問題 |
No.2741 Balanced Choice
|
| コンテスト | |
| ユーザー |
true-molecule
|
| 提出日時 | 2024-04-20 21:48:55 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 51 ms / 2,000 ms |
| コード長 | 709 bytes |
| コンパイル時間 | 1,111 ms |
| コンパイル使用メモリ | 98,536 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-12 20:04:17 |
| 合計ジャッジ時間 | 2,135 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 |
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
int main() {
using namespace std;
constexpr int INF = 1'000'000'000;
int n, max_w, d;
cin >> n >> max_w >> d;
vector<vector<int>> dp(2, vector<int>(max_w + 1, -INF));
for (auto&& i : dp)
i.at(0) = 0;
for (int t, w, v, i = 0; i < n; ++i) {
cin >> t >> w >> v;
for (int j = max_w; j >= w; --j)
dp.at(t).at(j) = max(dp.at(t).at(j), dp.at(t).at(j - w) + v);
}
int ans = 0;
for (int i = 0; i <= max_w; ++i)
for (int j = max(0, i - d); j <= min(max_w - i, i + d); ++j)
ans = max(ans, dp.at(0).at(i) + dp.at(1).at(j));
cout << ans << '\n';
return 0;
}
true-molecule