#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define all(a) a.begin() , a.end()
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>indexed_multiset;
void solve()
{
long long n;
cin >> n;
int a[n + 1] = {} , b[n + 1] = {} , c[n + 1] = {};
for(int i = 1; i <= n; i++)
cin >> a[i] >> b[i] >> c[i];
long long ans = 0, cur = 0 , r = 0 , sumb = 0, sumc = 0;
for(int i = 1; i <= n; i++)
{
cur -= c[i - 1];
sumb -= b[i - 1];
sumc -= c[i - 1];
while (r <= n && cur + c[r] >= a[r] - a[i])
cur += c[r] , sumb += b[r] , sumc += c[r] , r++;
ans = max(ans, sumb);
}
cout << ans << '\n';
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
// cin >> t;
while(t--)
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... |