#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("-O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define vec vector
#define sz(x) ( int)x.size()
#define m_p make_pair
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
typedef long long ll;
typedef pair<ll, int> pli;
typedef pair<int,ll> pil;
typedef pair<int,int> pii;
typedef unsigned long long ull;
auto rng=bind(uniform_int_distribution<int>(1,1000),mt19937(time(0)));
template<class T> bool umax(T &a,const T &b){return (a<b?a=b,1:0);}
template<class T> bool umin(T &a,const T &b){return (a>b?a=b,1:0);}
vec<ll>kek;
const int N=1e5+1;
ll f[N];
void upd(int id,ll x){
id++;
while(id<N){
umax(f[id],x);
id+=id&-id;
}
}
int get(int id){
id++;
ll ans=-2e9;
while(id>0){
umax(ans,f[id]);
id-=id&-id;
}
return ans;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n;
cin>>n;
vec<int>x(n),g(n),d(n);
vec<ll>pref(n,0);
vec<ll>pg(n,0);
for(int i=0;i<n;i++){
cin>>x[i]>>g[i]>>d[i];
pref[i]=(i?pref[i-1]:0)+d[i];
pg[i]=(i?pg[i-1]:0)+g[i];
}
for(int i=0;i<n;i++){
kek.pb(x[i]-pref[i]);
}
sort(all(kek));kek.erase(unique(all(kek)),kek.end());
ll ans=0;
for(int i=n-1;i>=0;i--){
int w=lower_bound(all(kek),x[i]-pref[i])-kek.begin();
// cerr<<x[i]-pref[i]<<endl;
upd(w,pg[i]);
w=upper_bound(all(kek),x[i]-(i?pref[i-1]:0))-kek.begin()-1;
umax(ans,get(w)-(i?pg[i-1]:0));
}
cout<<ans;
return 0;
}
/*
1 5
8
4 2 5 1 3
2 4
4 5
2 2 1 4
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |