結果

問題 No.974 最後の日までに
ユーザー 👑 jupirojupiro
提出日時 2020-01-19 14:21:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 1,914 bytes
コンパイル時間 1,493 ms
コンパイル使用メモリ 123,312 KB
実行使用メモリ 16,036 KB
最終ジャッジ日時 2024-04-14 21:59:18
合計ジャッジ時間 7,196 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
13,900 KB
testcase_01 AC 109 ms
14,556 KB
testcase_02 AC 106 ms
14,780 KB
testcase_03 AC 110 ms
14,804 KB
testcase_04 AC 109 ms
13,768 KB
testcase_05 AC 110 ms
15,512 KB
testcase_06 AC 109 ms
15,164 KB
testcase_07 AC 110 ms
13,900 KB
testcase_08 AC 108 ms
13,776 KB
testcase_09 AC 110 ms
13,924 KB
testcase_10 AC 110 ms
13,904 KB
testcase_11 AC 110 ms
13,972 KB
testcase_12 AC 110 ms
14,056 KB
testcase_13 AC 113 ms
14,248 KB
testcase_14 AC 110 ms
14,504 KB
testcase_15 AC 111 ms
13,900 KB
testcase_16 AC 109 ms
14,312 KB
testcase_17 AC 125 ms
13,788 KB
testcase_18 AC 127 ms
13,900 KB
testcase_19 AC 127 ms
14,684 KB
testcase_20 AC 129 ms
15,952 KB
testcase_21 AC 126 ms
13,768 KB
testcase_22 AC 126 ms
13,900 KB
testcase_23 AC 126 ms
14,584 KB
testcase_24 AC 127 ms
14,032 KB
testcase_25 AC 2 ms
6,940 KB
testcase_26 AC 2 ms
6,940 KB
testcase_27 AC 90 ms
12,348 KB
testcase_28 AC 112 ms
13,776 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 127 ms
13,768 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 1 ms
6,944 KB
testcase_33 AC 73 ms
9,784 KB
testcase_34 AC 117 ms
16,036 KB
testcase_35 AC 1 ms
6,944 KB
testcase_36 AC 2 ms
6,944 KB
testcase_37 AC 128 ms
14,344 KB
testcase_38 AC 2 ms
6,944 KB
testcase_39 AC 1 ms
6,940 KB
testcase_40 AC 76 ms
13,112 KB
testcase_41 AC 97 ms
13,772 KB
testcase_42 AC 128 ms
13,900 KB
testcase_43 AC 128 ms
13,900 KB
testcase_44 AC 100 ms
12,344 KB
testcase_45 AC 80 ms
9,656 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 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 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long MAX = 5100000;
const long long INF = 1LL << 60;
const long long mod = 1000000007LL;
//const long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

ll n;
vector<ll> a, b, c;

void dfs(ll cur, ll end, ll money, ll love, vector<pair<ll, ll>> &v) {
	if (cur == end) {
		v.emplace_back(money, love);
		return;
	}
	//cout << cur << " " << end << endl;
	dfs(cur + 1, end, money + a[cur], love, v);
	if (cur < end - 1) {
		dfs(cur + 2, end, money - c[cur + 1], love + b[cur + 1], v);
	}
}
ll solve(ll half) {
	vector<pair<ll,ll>> v1, v2;
	dfs(0, half, 0, 0, v1);
	dfs(half, n, 0, 0, v2);
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	for (ll i = (ll)v2.size() - 1; i > 0; i--) {
		chmax(v2[i - 1].second, v2[i].second);
	}
	ll res = 0;
	
	for (auto e : v1) {
		ll req = -e.first;
		auto itr = lower_bound(v2.begin(), v2.end(), make_pair(req, 0LL));
		if (itr == v2.end()) continue;
		chmax(res, itr->second + e.second);
	}
	
	return res;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	scanf("%lld", &n);
	a.resize(n), b.resize(n), c.resize(n); for (ll i = 0; i < n; i++) scanf("%lld %lld %lld", &a[i], &b[i], &c[i]);
	cout << max(solve(n / 2), solve(n / 2 + 1)) << endl;
	
	return 0;
}
0