#include<bits/stdc++.h>
using namespace std;
long long n,x[100005],g[100005],d[100005],cv[100005],f[100005],ans=0;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen(".inp","r",stdin);
// freopen(".out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x[i]>>g[i]>>d[i];
cv[i]=cv[i-1]+g[i];
f[i]=f[i-1]+d[i];
}
vector<long long> v,u;
v.push_back(f[0]-x[1]);
u.push_back(1);
ans=g[1];
for(int i=2;i<=n;i++)
{
long long vl=f[i-1]-x[i];
if(vl<v[v.size()-1]) {v.push_back(vl);u.push_back(i);}
long long k=f[i]-x[i];
long long l=0,r=v.size()-1,vt=-1;
while(l<=r)
{
long long mid=(l+r)/2;
if(v[mid]<=k)
{
r=mid-1;
vt=mid;
}
else l=mid+1;
}
// cout<<k<<' '<<vt<<endl;
if(vt==-1) continue;
long long h=u[vt];
// cout<<k<<' '<<h<<' '<<i<<endl;
ans=max(ans,cv[i]-cv[h-1]);
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
908 KB |
Output is correct |
24 |
Correct |
1 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
464 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
464 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
908 KB |
Output is correct |
24 |
Correct |
1 ms |
896 KB |
Output is correct |
25 |
Correct |
1 ms |
612 KB |
Output is correct |
26 |
Correct |
1 ms |
868 KB |
Output is correct |
27 |
Correct |
2 ms |
860 KB |
Output is correct |
28 |
Correct |
7 ms |
3224 KB |
Output is correct |
29 |
Correct |
9 ms |
3760 KB |
Output is correct |
30 |
Correct |
21 ms |
6996 KB |
Output is correct |
31 |
Correct |
14 ms |
6028 KB |
Output is correct |
32 |
Correct |
14 ms |
5992 KB |
Output is correct |
33 |
Correct |
15 ms |
5992 KB |
Output is correct |
34 |
Correct |
15 ms |
6828 KB |
Output is correct |
35 |
Correct |
19 ms |
8156 KB |
Output is correct |
36 |
Correct |
18 ms |
8292 KB |
Output is correct |