#include <bits/stdc++.h>
/**#pragma GCC optimize ("O3")
#pragma GCC optimize ("fast-math")
#pragma GCC optimize ("unroll-loops")**/
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define int long long
#define ll long long
#define all (x) begin(x), end (x)
#define xx first
#define yy second
using pii = pair <int, int>;
using tii = tuple <int, int, int>;
/**
#define cin fin
#define cout fout
**/
int n;
constexpr int NMAX = (int) 1e6+12;
#define ordered_set tree <int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
int x[NMAX], gold[NMAX], e[NMAX], lazy[NMAX];
inline void build_tree (int i, int st, int dr, int poz, int x)
{
if (st == dr)
{
lazy[i] = x;
return;
}
int mijl = (st + dr) >> 1;
if (mijl < poz){
build_tree ((i << 1) + 1, mijl + 1, dr, poz, x);
}
else
{
build_tree (i << 1, st, mijl, poz, x);
}
lazy[i] = max (lazy[i << 1], lazy[(i << 1) + 1]);
}
inline int query (int i, int st, int dr, int val)
{
if (st == dr)
return st;
int mijl = st + dr >> 1;
if (lazy[(i << 1) + 1] >= val)
return query((i << 1) + 1, mijl + 1, dr, val);
return query(i << 1, st, mijl, val);
}
main()
{
/**
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);**/
cin >> n;
int g, energy, i = 1;
for (;i <= n; ++ i)
{
cin >> x[i] >> g >> energy;
gold[i] = gold[i - 1] + g;
e[i] = e[i - 1] + energy;
build_tree(1, 1, n, i, e[i] - x[i]);
}
int maxi = 0;
for (;i<=n; ++ i)
{
int ans = query (1, 1, n, e[i - 1] - x[i]);
maxi = max (maxi, e[ans] - e[i - 1]);
}
cout << maxi;
//return 0 ^ 0;
}
Compilation message (stderr)
divide.cpp:58:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
58 | main()
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |