結果
| 問題 |
No.974 最後の日までに
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-19 14:21:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 119 ms / 2,000 ms |
| コード長 | 1,914 bytes |
| コンパイル時間 | 1,376 ms |
| コンパイル使用メモリ | 123,532 KB |
| 実行使用メモリ | 14,012 KB |
| 最終ジャッジ日時 | 2024-10-04 01:41:24 |
| 合計ジャッジ時間 | 6,119 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 49 |
ソースコード
#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;
}