結果
| 問題 |
No.974 最後の日までに
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-18 07:54:02 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 167 ms / 2,000 ms |
| コード長 | 1,851 bytes |
| コンパイル時間 | 1,824 ms |
| コンパイル使用メモリ | 178,604 KB |
| 実行使用メモリ | 23,816 KB |
| 最終ジャッジ日時 | 2024-10-04 01:36:44 |
| 合計ジャッジ時間 | 8,815 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(15);
int N; cin >> N;
vector<ll> A(N), B(N), C(N); rep(i, N) cin >> A[i] >> B[i] >> C[i];
auto solve = [&](int n1, int n2) -> ll {
if (n1 < 0 or n2 < 0) return LLONG_MIN;
auto dfs = [&](auto dfs, int l, int r, ll money, ll like, bool promise, vector<pair<ll, ll>> &res) -> void {
if (l == r) {
if (r == N or not promise) {
res.emplace_back(money, like);
}
return;
}
if (promise) {
dfs(dfs, l + 1, r, money - C[l], like + B[l], false, res);
} else {
dfs(dfs, l + 1, r, money, like, true, res);
dfs(dfs, l + 1, r, money + A[l], like, false, res);
}
};
vector<pair<ll, ll>> fst, snd; // (money, like)
dfs(dfs, 0, n1, 0, 0, false, fst);
dfs(dfs, n1, N, 0, 0, false, snd);
sort(range(fst));
sort(range(snd));
auto normalize = [](vector<pair<ll, ll>> a) -> vector<pair<ll, ll>> {
vector<pair<ll, ll>> res;
for (auto p : a) {
while (not res.empty() and res.back().second <= p.second) {
res.pop_back();
}
res.push_back(p);
}
return res;
};
fst = normalize(fst);
snd = normalize(snd);
int k = (int)snd.size() - 1;
ll ans = LLONG_MIN;
for (auto p : fst) {
while (k >= 1 and p.first + snd[k - 1].first >= 0) k--;
if (p.first + snd[k].first >= 0) {
ans = max(ans, p.second + snd[k].second);
}
}
return ans;
};
ll ans = max(solve(N / 2, (N + 1) / 2), solve(N / 2 + 1, (N + 1) / 2 - 1));
cout << ans << endl;
}