#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;
vector <pair <long long,int> > v;
int n,x[N],g[N],d[N],seg[N << 2];
long long ans,pred[N],preg[N],a[N],b[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++) {
int lst = get(1,1,2 * n,1,a[i]);
ans = max(ans,1ll * g[i]);
if (lst != INF) 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: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]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1912 KB |
Output is correct |
2 |
Correct |
3 ms |
2024 KB |
Output is correct |
3 |
Correct |
3 ms |
2024 KB |
Output is correct |
4 |
Correct |
3 ms |
2024 KB |
Output is correct |
5 |
Correct |
3 ms |
2180 KB |
Output is correct |
6 |
Correct |
4 ms |
2280 KB |
Output is correct |
7 |
Correct |
3 ms |
2280 KB |
Output is correct |
8 |
Correct |
3 ms |
2280 KB |
Output is correct |
9 |
Correct |
5 ms |
2280 KB |
Output is correct |
10 |
Correct |
4 ms |
2280 KB |
Output is correct |
11 |
Correct |
4 ms |
2280 KB |
Output is correct |
12 |
Correct |
3 ms |
2280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2280 KB |
Output is correct |
2 |
Correct |
4 ms |
2280 KB |
Output is correct |
3 |
Correct |
3 ms |
2280 KB |
Output is correct |
4 |
Correct |
4 ms |
2280 KB |
Output is correct |
5 |
Correct |
4 ms |
2280 KB |
Output is correct |
6 |
Correct |
4 ms |
2280 KB |
Output is correct |
7 |
Correct |
4 ms |
2280 KB |
Output is correct |
8 |
Correct |
4 ms |
2280 KB |
Output is correct |
9 |
Correct |
5 ms |
2284 KB |
Output is correct |
10 |
Correct |
5 ms |
2412 KB |
Output is correct |
11 |
Correct |
7 ms |
2792 KB |
Output is correct |
12 |
Correct |
11 ms |
2792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
2792 KB |
Output is correct |
2 |
Correct |
10 ms |
3060 KB |
Output is correct |
3 |
Correct |
12 ms |
3060 KB |
Output is correct |
4 |
Correct |
48 ms |
6036 KB |
Output is correct |
5 |
Correct |
51 ms |
6036 KB |
Output is correct |
6 |
Correct |
103 ms |
9696 KB |
Output is correct |
7 |
Correct |
89 ms |
9696 KB |
Output is correct |
8 |
Correct |
90 ms |
9696 KB |
Output is correct |
9 |
Correct |
88 ms |
9696 KB |
Output is correct |
10 |
Incorrect |
144 ms |
9696 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |