This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |