#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, 1, n * 2, nerf[0], 0);
int res = 0;
for(int i=1; i<=n; i++)
{
int val = nerf[sum[i].se - x[i]];
update(1, 1, n * 2, nerf[sum[i - 1].se - x[i]], sum[i - 1].fi);
res = max(res, sum[i].fi - get(1, 1, n * 2, 0, val));
// 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 |
1 |
Correct |
12 ms |
31572 KB |
Output is correct |
2 |
Correct |
14 ms |
31572 KB |
Output is correct |
3 |
Correct |
15 ms |
31572 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
13 ms |
31676 KB |
Output is correct |
6 |
Correct |
13 ms |
31656 KB |
Output is correct |
7 |
Correct |
14 ms |
31572 KB |
Output is correct |
8 |
Correct |
14 ms |
31628 KB |
Output is correct |
9 |
Correct |
15 ms |
31672 KB |
Output is correct |
10 |
Correct |
15 ms |
31616 KB |
Output is correct |
11 |
Correct |
16 ms |
31576 KB |
Output is correct |
12 |
Correct |
15 ms |
31584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
31572 KB |
Output is correct |
2 |
Correct |
14 ms |
31572 KB |
Output is correct |
3 |
Correct |
15 ms |
31572 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
13 ms |
31676 KB |
Output is correct |
6 |
Correct |
13 ms |
31656 KB |
Output is correct |
7 |
Correct |
14 ms |
31572 KB |
Output is correct |
8 |
Correct |
14 ms |
31628 KB |
Output is correct |
9 |
Correct |
15 ms |
31672 KB |
Output is correct |
10 |
Correct |
15 ms |
31616 KB |
Output is correct |
11 |
Correct |
16 ms |
31576 KB |
Output is correct |
12 |
Correct |
15 ms |
31584 KB |
Output is correct |
13 |
Correct |
18 ms |
31700 KB |
Output is correct |
14 |
Correct |
13 ms |
31624 KB |
Output is correct |
15 |
Correct |
14 ms |
31700 KB |
Output is correct |
16 |
Correct |
14 ms |
31700 KB |
Output is correct |
17 |
Correct |
14 ms |
31828 KB |
Output is correct |
18 |
Correct |
17 ms |
31860 KB |
Output is correct |
19 |
Correct |
17 ms |
31820 KB |
Output is correct |
20 |
Correct |
14 ms |
31828 KB |
Output is correct |
21 |
Correct |
16 ms |
31956 KB |
Output is correct |
22 |
Correct |
20 ms |
32008 KB |
Output is correct |
23 |
Correct |
20 ms |
32616 KB |
Output is correct |
24 |
Correct |
23 ms |
32640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
31572 KB |
Output is correct |
2 |
Correct |
14 ms |
31572 KB |
Output is correct |
3 |
Correct |
15 ms |
31572 KB |
Output is correct |
4 |
Correct |
13 ms |
31572 KB |
Output is correct |
5 |
Correct |
13 ms |
31676 KB |
Output is correct |
6 |
Correct |
13 ms |
31656 KB |
Output is correct |
7 |
Correct |
14 ms |
31572 KB |
Output is correct |
8 |
Correct |
14 ms |
31628 KB |
Output is correct |
9 |
Correct |
15 ms |
31672 KB |
Output is correct |
10 |
Correct |
15 ms |
31616 KB |
Output is correct |
11 |
Correct |
16 ms |
31576 KB |
Output is correct |
12 |
Correct |
15 ms |
31584 KB |
Output is correct |
13 |
Correct |
18 ms |
31700 KB |
Output is correct |
14 |
Correct |
13 ms |
31624 KB |
Output is correct |
15 |
Correct |
14 ms |
31700 KB |
Output is correct |
16 |
Correct |
14 ms |
31700 KB |
Output is correct |
17 |
Correct |
14 ms |
31828 KB |
Output is correct |
18 |
Correct |
17 ms |
31860 KB |
Output is correct |
19 |
Correct |
17 ms |
31820 KB |
Output is correct |
20 |
Correct |
14 ms |
31828 KB |
Output is correct |
21 |
Correct |
16 ms |
31956 KB |
Output is correct |
22 |
Correct |
20 ms |
32008 KB |
Output is correct |
23 |
Correct |
20 ms |
32616 KB |
Output is correct |
24 |
Correct |
23 ms |
32640 KB |
Output is correct |
25 |
Correct |
19 ms |
32628 KB |
Output is correct |
26 |
Correct |
25 ms |
33328 KB |
Output is correct |
27 |
Correct |
26 ms |
33496 KB |
Output is correct |
28 |
Correct |
86 ms |
40060 KB |
Output is correct |
29 |
Correct |
103 ms |
41124 KB |
Output is correct |
30 |
Correct |
166 ms |
51012 KB |
Output is correct |
31 |
Correct |
164 ms |
49916 KB |
Output is correct |
32 |
Correct |
174 ms |
49820 KB |
Output is correct |
33 |
Correct |
161 ms |
49700 KB |
Output is correct |
34 |
Correct |
151 ms |
49272 KB |
Output is correct |
35 |
Correct |
165 ms |
50200 KB |
Output is correct |
36 |
Correct |
169 ms |
50468 KB |
Output is correct |