#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define len(a) (int)a.size()
#define fi first
#define sc second
#define cout maltahsin
#define left ind + ind
#define right ind + ind + 1
#define mid (l + r) / 2
#define d1(w) cerr<<#w<<":"<<w<<endl;
#define d2(w,c) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<endl;
#define d3(w,c,z) cerr<<#w<<":"<<w<<" "<<#c<<":"<<c<<" "<<#z<<":"<<z<<endl;
#define FAST_IO ios_base::sync_with_stdio(false);
#define endl '\n'
const int maxn = 620;
const long long LINF = 1e18;
const int LOG = 31;
const int INF = 1e9 + 5;
const int N = 1e5 + 5;
const int M = 1e5 + 5;
const int SQ = 350;
const int MOD = 998244353;
typedef pair <int,int> pii;
map <long long,int> mpx;
vector <pair <long long,int> > v;
int n,x[N],g[N],d[N],a[N],b[N],seg[N << 2];
long long ans,pred[N],preg[N];
void update(int ind,int l,int r,int w,int val) {
if (l > w || r < w) return;
if (l == w && r == w) {
seg[ind] = max(seg[ind],val);
return;
}
update(left,l,mid,w,val);
update(right,mid + 1,r,w,val);
seg[ind] = max(seg[left],seg[right]);
}
int get(int ind,int l,int r,int lw,int rw) {
if (l > rw || r < lw) return 0;
if (l >= lw && r <= rw) return seg[ind];
return max(get(left,l,mid,lw,rw),get(right,mid + 1,r,lw,rw));
}
int main() {
scanf("%d",&n);
for (int i = 1 ; i <= n ; i++) {
scanf("%d %d %d",&x[i],&g[i],&d[i]);
pred[i] = pred[i - 1] + d[i];
preg[i] = preg[i - 1] + g[i];
a[i] = pred[i] - x[i];
b[i] = pred[i - 1] - x[i];
v.pb(mp(a[i],i));
v.pb(mp(b[i],i));
}
sort(v.begin(),v.end());
for (int i = 0, lst = 0; i < len(v) ; i++) {
if (i == 0 || v[i - 1].fi != v[i].fi) lst++;
if (b[v[i].sc]) a[v[i].sc] = lst;
else b[v[i].sc] = lst;
}
for (int i = 1 ; i <= n ; i++) {
int lst = -get(1,1,2 * n,1,a[i]);
ans = max(ans,1ll * g[i]);
if (lst) ans = max(preg[i] - preg[lst - 1],ans);
update(1,1,2 * n,b[i],-i);
}
printf("%lld\n",ans);
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:57:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
divide.cpp:60:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&x[i],&g[i],&d[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Incorrect |
3 ms |
488 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
1160 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |