#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF 1e18
#define f first
#define s second
#define pii pair<int, int>
#define vi vector<int>
const int MOD = 1'000'000'000 + 7;
void setIO(string name = "")
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#ifdef LOCAL
freopen("inp.txt", "r", stdin);
freopen("out.txt", "w", stdout);
#else
if (!name.empty())
{
freopen((name + ".INP").c_str(), "r", stdin);
freopen((name + ".OUT").c_str(), "w", stdout);
}
#endif
}
// START OF DEBUG
#define db(val) "["#val" = "<<(val)<<"] "
#define print_op(...) ostream& operator<<(ostream& out, const __VA_ARGS__& u)
// for printing std::pair
template<class U, class V> print_op(pair<U, V>) {
return out << "(" << u.first << ", " << u.second << ")";
}
// for printing collection
template<class Con, class = decltype(begin(declval<Con>()))>
typename enable_if<!is_same<Con, string>::value, ostream&>::type
operator<<(ostream& out, const Con& con) {
out << "{";
for (auto beg = con.begin(), it = beg; it != con.end(); ++it)
out << (it == beg ? "" : ", ") << *it;
return out << "}";
}
// for printing std::tuple
template<size_t i, class T> ostream& print_tuple_utils(ostream& out, const T& tup) {
if constexpr(i == tuple_size<T>::value) return out << ")";
else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup);
}
template<class ...U> print_op(tuple<U...>) {
return print_tuple_utils<0, tuple<U...>>(out, u);
}
// END OF DEBUG
//
struct Compressor {
vi v;
int sz() { return (int)v.size(); }
void add(int x) {
v.push_back(x);
}
void init() {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
int id(int key) {
return lower_bound(v.begin(), v.end(), key) - v.begin() + 1;
}
};
const int MAXN = 2e5;
struct Camp {
int x = 0, g = 0, d = 0;
int pd = 0, pg = 0;
} a[MAXN + 5];
int bit[MAXN + 5];
void upd(int pos, int val) {
// cout << "update: " << pos << ' ' << val << '\n';
while(pos <= MAXN) {
bit[pos] = max(bit[pos], val);
pos += pos & (-pos);
}
}
int get(int pos) {
int res = -INF;
while(pos > 0) {
res = max(res, bit[pos]);
pos -= pos & (-pos);
}
return res;
}
void solve()
{
int n; cin >> n;
for(int i = 1; i <= MAXN; i++) bit[i] = -INF;
for(int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].g >> a[i].d;
a[i].pd = a[i - 1].pd + a[i].d;
a[i].pg = a[i - 1].pg + a[i].g;
// cout << a[i].x << ' ' << a[i].pd << ' ' << a[i].pg << '\n';
}
Compressor cmp;
for(int i = 1; i <= n; i++) {
cmp.add(a[i].pd - a[i].x);
cmp.add(a[i].pd - a[i].d - a[i].x);
}
cmp.init();
// cout << cmp.v << '\n';
// solve
int res = 0;
for(int i = 1; i <= n; i++) {
res = max(res, a[i].g);
// for(int j = 1; j <= 20; j++) cout << bit[i] << ' '; cout << '\n';
// cout << db(i) << ' ' << cmp.id(a[i].pd - a[i].x) << '\n';
res = max(res, a[i].pg + get(cmp.id(a[i].pd - a[i].x)));
// cout << res << '\n';
upd(cmp.id(a[i].pd - a[i].d - a[i].x), -a[i].pg + a[i].g);
}
cout << res << '\n';
}
signed main()
{
setIO();
int t = 1;
// cin >> t;
while (t--)
solve();
}
Compilation message (stderr)
divide.cpp: In function 'void setIO(std::string)':
divide.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen((name + ".INP").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
divide.cpp:24:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen((name + ".OUT").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |