結果
問題 | No.974 最後の日までに |
ユーザー | QCFium |
提出日時 | 2020-01-17 22:37:27 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,501 bytes |
コンパイル時間 | 2,124 ms |
コンパイル使用メモリ | 178,572 KB |
実行使用メモリ | 4,512 KB |
最終ジャッジ日時 | 2023-09-08 05:01:11 |
合計ジャッジ時間 | 9,757 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | RE | - |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | RE | - |
testcase_05 | RE | - |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | RE | - |
testcase_22 | RE | - |
testcase_23 | RE | - |
testcase_24 | RE | - |
testcase_25 | RE | - |
testcase_26 | RE | - |
testcase_27 | RE | - |
testcase_28 | RE | - |
testcase_29 | AC | 2 ms
4,380 KB |
testcase_30 | RE | - |
testcase_31 | WA | - |
testcase_32 | AC | 2 ms
4,380 KB |
testcase_33 | RE | - |
testcase_34 | RE | - |
testcase_35 | RE | - |
testcase_36 | AC | 1 ms
4,384 KB |
testcase_37 | RE | - |
testcase_38 | AC | 2 ms
4,380 KB |
testcase_39 | AC | 2 ms
4,384 KB |
testcase_40 | RE | - |
testcase_41 | RE | - |
testcase_42 | RE | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | RE | - |
testcase_47 | RE | - |
testcase_48 | RE | - |
testcase_49 | AC | 1 ms
4,384 KB |
testcase_50 | RE | - |
testcase_51 | RE | - |
ソースコード
#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(); assert(n <= 3); if (n == 1) { std::cout << -1 << 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; }