結果

問題 No.974 最後の日までに
ユーザー QCFiumQCFium
提出日時 2020-01-17 22:35:59
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,484 bytes
コンパイル時間 1,894 ms
コンパイル使用メモリ 178,928 KB
実行使用メモリ 17,480 KB
最終ジャッジ日時 2023-09-08 04:57:35
合計ジャッジ時間 10,263 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 165 ms
16,108 KB
testcase_01 AC 161 ms
16,612 KB
testcase_02 AC 161 ms
16,924 KB
testcase_03 AC 162 ms
16,120 KB
testcase_04 AC 160 ms
16,884 KB
testcase_05 AC 159 ms
16,360 KB
testcase_06 AC 159 ms
16,824 KB
testcase_07 AC 159 ms
17,156 KB
testcase_08 AC 161 ms
16,580 KB
testcase_09 AC 161 ms
16,040 KB
testcase_10 AC 164 ms
16,392 KB
testcase_11 AC 164 ms
16,884 KB
testcase_12 AC 165 ms
17,132 KB
testcase_13 AC 162 ms
16,640 KB
testcase_14 AC 163 ms
16,720 KB
testcase_15 AC 162 ms
16,056 KB
testcase_16 AC 166 ms
16,588 KB
testcase_17 AC 126 ms
16,772 KB
testcase_18 AC 128 ms
16,120 KB
testcase_19 AC 129 ms
16,316 KB
testcase_20 AC 131 ms
17,480 KB
testcase_21 AC 128 ms
16,308 KB
testcase_22 AC 131 ms
16,612 KB
testcase_23 AC 128 ms
16,608 KB
testcase_24 AC 128 ms
16,908 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 127 ms
13,112 KB
testcase_28 AC 168 ms
16,168 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 135 ms
16,320 KB
testcase_31 WA -
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 102 ms
11,160 KB
testcase_34 AC 168 ms
16,176 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 144 ms
17,120 KB
testcase_38 AC 1 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 95 ms
13,132 KB
testcase_41 AC 128 ms
16,596 KB
testcase_42 AC 147 ms
16,440 KB
testcase_43 AC 147 ms
16,128 KB
testcase_44 AC 110 ms
13,108 KB
testcase_45 AC 91 ms
11,092 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,376 KB
testcase_49 AC 2 ms
4,380 KB
testcase_50 AC 1 ms
4,380 KB
testcase_51 AC 1 ms
4,380 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 << -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;
}
0