#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()
#define int long long
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();
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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
452 KB |
Output is correct |
23 |
Correct |
3 ms |
752 KB |
Output is correct |
24 |
Correct |
3 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
452 KB |
Output is correct |
23 |
Correct |
3 ms |
752 KB |
Output is correct |
24 |
Correct |
3 ms |
716 KB |
Output is correct |
25 |
Correct |
3 ms |
716 KB |
Output is correct |
26 |
Correct |
5 ms |
1100 KB |
Output is correct |
27 |
Correct |
5 ms |
1100 KB |
Output is correct |
28 |
Correct |
26 ms |
4192 KB |
Output is correct |
29 |
Correct |
31 ms |
4584 KB |
Output is correct |
30 |
Correct |
57 ms |
8716 KB |
Output is correct |
31 |
Correct |
50 ms |
7568 KB |
Output is correct |
32 |
Correct |
51 ms |
7744 KB |
Output is correct |
33 |
Correct |
51 ms |
7556 KB |
Output is correct |
34 |
Correct |
50 ms |
7568 KB |
Output is correct |
35 |
Correct |
52 ms |
8068 KB |
Output is correct |
36 |
Correct |
55 ms |
8384 KB |
Output is correct |