#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 = 2e5 + 5;
const int M = 1e5 + 5;
const int SQ = 350;
const int MOD = 998244353;
typedef pair <int,int> pii;
vector <pair <long long,int> > v;
int n,x[N],g[N],d[N],seg[N << 2],a[N],b[N];
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] = min(seg[ind],val);
return;
}
update(left,l,mid,w,val);
update(right,mid + 1,r,w,val);
seg[ind] = min(seg[left],seg[right]);
}
int get(int ind,int l,int r,int lw,int rw) {
if (l > rw || r < lw) return INF;
if (l >= lw && r <= rw) return seg[ind];
return min(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];
v.pb(mp(pred[i] - x[i],i));
v.pb(mp(pred[i - 1] - x[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 = 0 ; i < (N << 2) ; i++) seg[i] = INF;
for (int i = 1 ; i <= n ; i++) {
update(1,1,2 * n,b[i],i);
int lst = get(1,1,2 * n,1,a[i]);
if (lst != INF) ans = max(preg[i] - preg[lst - 1],ans);
}
printf("%lld\n",ans);
}
Compilation message
divide.cpp: In function 'int main()':
divide.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
~~~~~^~~~~~~~~
divide.cpp:58: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]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
3448 KB |
Output is correct |
2 |
Correct |
6 ms |
3576 KB |
Output is correct |
3 |
Correct |
5 ms |
3576 KB |
Output is correct |
4 |
Correct |
4 ms |
3596 KB |
Output is correct |
5 |
Correct |
6 ms |
3596 KB |
Output is correct |
6 |
Correct |
6 ms |
3596 KB |
Output is correct |
7 |
Correct |
5 ms |
3720 KB |
Output is correct |
8 |
Correct |
5 ms |
3720 KB |
Output is correct |
9 |
Correct |
6 ms |
3720 KB |
Output is correct |
10 |
Correct |
5 ms |
3720 KB |
Output is correct |
11 |
Correct |
6 ms |
3720 KB |
Output is correct |
12 |
Correct |
5 ms |
3720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
3720 KB |
Output is correct |
2 |
Correct |
6 ms |
3720 KB |
Output is correct |
3 |
Correct |
5 ms |
3736 KB |
Output is correct |
4 |
Correct |
7 ms |
3736 KB |
Output is correct |
5 |
Correct |
6 ms |
3736 KB |
Output is correct |
6 |
Correct |
8 ms |
3940 KB |
Output is correct |
7 |
Correct |
6 ms |
3940 KB |
Output is correct |
8 |
Correct |
7 ms |
3940 KB |
Output is correct |
9 |
Correct |
6 ms |
3940 KB |
Output is correct |
10 |
Correct |
7 ms |
3940 KB |
Output is correct |
11 |
Correct |
10 ms |
4164 KB |
Output is correct |
12 |
Correct |
13 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
4320 KB |
Output is correct |
2 |
Correct |
14 ms |
4456 KB |
Output is correct |
3 |
Correct |
13 ms |
4580 KB |
Output is correct |
4 |
Correct |
49 ms |
7228 KB |
Output is correct |
5 |
Correct |
68 ms |
7228 KB |
Output is correct |
6 |
Correct |
134 ms |
10592 KB |
Output is correct |
7 |
Correct |
95 ms |
10592 KB |
Output is correct |
8 |
Correct |
121 ms |
10592 KB |
Output is correct |
9 |
Correct |
100 ms |
10592 KB |
Output is correct |
10 |
Correct |
118 ms |
10592 KB |
Output is correct |
11 |
Correct |
127 ms |
10632 KB |
Output is correct |
12 |
Correct |
101 ms |
10632 KB |
Output is correct |