結果
| 問題 |
No.974 最後の日までに
|
| コンテスト | |
| ユーザー |
QCFium
|
| 提出日時 | 2020-01-17 22:39:52 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 172 ms / 2,000 ms |
| コード長 | 1,483 bytes |
| コンパイル時間 | 2,000 ms |
| コンパイル使用メモリ | 180,520 KB |
| 実行使用メモリ | 16,584 KB |
| 最終ジャッジ日時 | 2024-10-04 01:28:33 |
| 合計ジャッジ時間 | 9,064 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
#include <bits/stdc++.h>
int ri() {
int n;
scanf("%d", &n);
return n;
}
struct Info {
int64_t get;
int64_t score;
int64_t lose;
};
// {money, score}
std::vector<std::pair<int64_t, int64_t> > solve(const std::vector<Info> &a, int head) {
int n = a.size();
if (n == head) return {{0, 0}};
std::vector<std::pair<int64_t, int64_t> > res = solve(a, head + 1);
for (auto &i : res) i.first += a[head].get;
if (head + 1 < n) {
auto tmp = solve(a, head + 2);
for (auto &i : tmp) i.first -= a[head + 1].lose, i.second += a[head + 1].score;
res.insert(res.end(), tmp.begin(), tmp.end());
}
return res;
}
int main() {
int n = ri();
if (n == 1) {
std::cout << 0 << std::endl;
return 0;
}
std::vector<Info> a(n);
for (auto &i : a) std::cin >> i.get >> i.score >> i.lose;
int half = n / 2;
int64_t res = 0;
auto merge = [&] (int split) {
auto r0 = solve(std::vector<Info>(a.begin(), a.begin() + split), 0);
auto r1 = solve(std::vector<Info>(a.begin() + split, a.end()), 0);
std::sort(r1.begin(), r1.end(), [] (auto i, auto j) { return i.first > j.first; });
int64_t max = -1000000000000000000;
int head = 0;
std::sort(r0.begin(), r0.end(), [] (auto i, auto j) { return i.first < j.first; });
for (auto &i : r0) {
while (head < (int) r1.size() && r1[head].first + i.first >= 0) max = std::max(max, r1[head].second), head++;
res = std::max(res, max + i.second);
}
};
merge(half);
merge(half + 1);
std::cout << res << std::endl;
return 0;
}
QCFium