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>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n;
int x[maxN], g[maxN], d[maxN];
pair<int, int> sum[maxN];
map<int, int> nerf;
void ReadInput()
{
vector<int> vc;
cin >> n;
for(int i=1; i<=n; i++)
{
cin >> x[i] >> g[i] >> d[i];
sum[i] = {sum[i - 1].fi + g[i], sum[i - 1].se + d[i]};
vc.pb(sum[i].se - x[i]);
vc.pb(sum[i - 1].se - x[i]);
}
vc.pb(0);
sort(vc.begin(), vc.end());
int p = 0;
for(int v : vc)
{
if(nerf[v]) continue;
nerf[v] = ++p;
}
}
int st[4 * maxN];
void update(int id, int l, int r, int pos, int val)
{
if(l > pos || r < pos) return;
if(l == r && l == pos)
{
st[id] = min(st[id], val);
return;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, pos, val);
update(id * 2 + 1, mid + 1, r, pos, val);
st[id] = min(st[id * 2], st[id * 2 + 1]);
}
int get(int id, int l, int r, int u, int v)
{
if(l > v || r < u) return oo;
if(l >= u && r <= v) return st[id];
int mid = (l + r) / 2;
return min(get(id * 2, l, mid, u, v), get(id * 2 + 1, mid + 1, r, u, v));
}
void Solve()
{
memset(st, 3, sizeof st);
update(1, 0, n * 2, nerf[0], 0);
int res = 0;
for(int i=1; i<=n; i++)
{
int val = nerf[sum[i].se - x[i]];
res = max(res, sum[i].fi - get(1, 0, n * 2, 0, val));
update(1, 0, n * 2, nerf[sum[i - 1].se - x[i]], sum[i - 1].fi);
// cout << res << " ";
}
cout << res;
}
int32_t main()
{
//freopen("x.inp", "r", stdin);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ReadInput();
Solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |