#include <bits/stdc++.h>
//#include "ext/pb_ds/assoc_container.hpp"
//#include "ext/pb_ds/tree_policy.hpp"
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef string str;
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
//#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//void freo(str x) {freopen((x + ".in").c_str(), "r", stdin);freopen((x + ".out").c_str(), "w", stdout);}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
ll x[n], g[n], d[n];
for (int i = 0; i < n; i++) cin >> x[i] >> g[i] >> d[i];
ll ans = *max_element(g, g + n);
vector <ll> pref_d(n), pref_g(n), pref_need;
pref_d[0] = d[0];
pref_g[0] = g[0];
pref_need.pb(x[0] - d[0]);
ll need = x[0] - d[0];
for (int i = 1; i < n; i++) {
pref_d[i] = pref_d[i - 1] + d[i];
pref_g[i] = pref_g[i - 1] + g[i];
need = x[i] - pref_d[i];
pref_need.pb(max(pref_need.back(), need));
if (need <= 0) ans = max(ans, pref_g[i]);
else {
auto it = lower_bound(all(pref_need), need);
int ind = it - pref_need.begin();
ans = max(ans, pref_g[i] - pref_g[ind]);
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |