제출 #98345

#제출 시각아이디문제언어결과실행 시간메모리
98345luciocf금 캐기 (IZhO14_divide)C++14
100 / 100
162 ms8184 KiB
#include <bits/stdc++.h>

using namespace std;

const int maxn = 1e5+10;
const int inf = 1e9+10;

typedef long long ll;

int x[maxn], g[maxn], d[maxn];

ll s[maxn], p[maxn];

ll tree[4*maxn];

void build(int node, int l, int r)
{
	if (l == r)
	{
		tree[node] = s[l-1]-x[l];
		return;
	}

	int mid = (l+r)>>1;

	build(2*node, l, mid); build(2*node+1, mid+1, r);

	tree[node] = min(tree[2*node], tree[2*node+1]);
}

int query(int node, int l, int r, ll v)
{
	if (l == r)
	{
		if (tree[node] <= v) return l;
		return inf;
	}

	int mid = (l+r)>>1;

	if (tree[2*node] <= v) return query(2*node, l, mid, v);
	return query(2*node+1, mid+1, r, v);
}

int main(void)
{
	int n;
	cin >> n;

	for (int i = 1; i <= n; i++)
	{
		cin >> x[i] >> g[i] >> d[i];

		s[i] = s[i-1]+(ll)d[i];
		p[i] = p[i-1]+(ll)g[i];
	}

	build(1, 1, n);

	ll ans = 0LL;

	for (int i = 1; i <= n; i++)
	{
		int pos = query(1, 1, n, s[i]-(ll)x[i]);

		if (pos != inf && pos <= i) ans = max(ans, p[i]-p[pos-1]);
	}

	cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...