結果

問題 No.974 最後の日までに
ユーザー kyo1
提出日時 2020-06-16 15:28:18
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,389 bytes
コンパイル時間 2,567 ms
コンパイル使用メモリ 202,892 KB
最終ジャッジ日時 2025-01-11 04:38:01
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 49
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
const int64_t INF = INT64_C(1) << 60;
template <typename T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int W;
cin >> W;
vector<int64_t> A(W), B(W), C(W);
for (int i = 0; i < W; i++) {
cin >> A[i] >> B[i] >> C[i];
}
function<void(int, int, int64_t, int64_t, vector<pair<int64_t, int64_t>> &)> dfs =
[&](int now, int end, int64_t money, int64_t love, vector<pair<int64_t, int64_t>> &vec) {
if (now == end) {
vec.emplace_back(make_pair(money, love));
return;
}
dfs(now + 1, end, money + A[now], love, vec);
if (now + 1 < end) dfs(now + 2, end, money - C[now + 1], love + B[now + 1], vec);
};
auto solve = [&](int w) {
vector<pair<int64_t, int64_t>> A, B;
dfs(0, w, 0, 0, A);
dfs(w, W, 0, 0, B);
sort(B.begin(), B.end());
for (int i = (int)B.size() - 2; i > -1; i--) {
chmax(B[i].second, B[i + 1].second);
}
int64_t res = 0;
for (int i = 0; i < (int)A.size(); i++) {
auto itr = lower_bound(B.begin(), B.end(), make_pair(-A[i].first, -INF));
if (itr != B.end()) res = max(res, itr->second + A[i].second);
}
return res;
};
cout << max(solve(W / 2), solve(W / 2 + 1)) << '\n';
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0