結果

問題 No.974 最後の日までに
ユーザー QCFiumQCFium
提出日時 2020-01-17 22:39:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 1,483 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 177,516 KB
実行使用メモリ 17,580 KB
最終ジャッジ日時 2024-04-14 21:48:25
合計ジャッジ時間 8,714 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 155 ms
16,656 KB
testcase_01 AC 152 ms
16,488 KB
testcase_02 AC 155 ms
16,824 KB
testcase_03 AC 161 ms
17,088 KB
testcase_04 AC 152 ms
16,500 KB
testcase_05 AC 150 ms
16,708 KB
testcase_06 AC 153 ms
16,560 KB
testcase_07 AC 153 ms
17,412 KB
testcase_08 AC 158 ms
16,964 KB
testcase_09 AC 158 ms
17,236 KB
testcase_10 AC 152 ms
16,448 KB
testcase_11 AC 152 ms
16,440 KB
testcase_12 AC 152 ms
17,580 KB
testcase_13 AC 153 ms
16,504 KB
testcase_14 AC 155 ms
17,456 KB
testcase_15 AC 156 ms
16,416 KB
testcase_16 AC 150 ms
16,720 KB
testcase_17 AC 118 ms
16,784 KB
testcase_18 AC 121 ms
16,564 KB
testcase_19 AC 120 ms
16,464 KB
testcase_20 AC 127 ms
17,064 KB
testcase_21 AC 121 ms
16,836 KB
testcase_22 AC 124 ms
16,884 KB
testcase_23 AC 118 ms
17,444 KB
testcase_24 AC 120 ms
16,516 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 3 ms
6,940 KB
testcase_27 AC 118 ms
13,324 KB
testcase_28 AC 165 ms
16,748 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 128 ms
16,596 KB
testcase_31 AC 2 ms
6,940 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 101 ms
11,536 KB
testcase_34 AC 163 ms
17,352 KB
testcase_35 AC 1 ms
6,944 KB
testcase_36 AC 2 ms
6,940 KB
testcase_37 AC 135 ms
17,164 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 89 ms
13,344 KB
testcase_41 AC 121 ms
16,340 KB
testcase_42 AC 139 ms
16,700 KB
testcase_43 AC 136 ms
17,252 KB
testcase_44 AC 99 ms
13,692 KB
testcase_45 AC 83 ms
11,620 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 1 ms
6,940 KB
testcase_48 AC 2 ms
6,940 KB
testcase_49 AC 2 ms
6,940 KB
testcase_50 AC 2 ms
6,944 KB
testcase_51 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0