#include <iostream>
#include <cstdio>
#define pairr pair<long long,int>
#define f first
#define s second
using namespace std;
long long sumg[100010],sume[100010],a;
int n,x[100010],g[100010],e[100010],il,ir;
pairr sl[100010],sr[100010];
long long solve(int l, int r)
{
if (l==r)
{
return g[l];
}
if (l==r-1)
{
if (e[l]+e[r]>=x[r]-x[l]) return g[l]+g[r];
else return max(g[l],g[r]);
}
int mid=(l+r)/2;
long long ans=max(solve(l,mid),solve(mid+1,r));
il=0;
ir=0;
for (int i=mid;i>=0;i--)
{
a=(i==0 ? sume[mid] : sume[mid]-sume[i-1])-(x[mid]-x[i]);
while (il>0 && a>=sl[il-1].f)
{
il--;
}
sl[il].f=a;
sl[il].s=i;
il++;
}
for (int i=mid+1;i<=r;i++)
{
a=sume[i]-sume[mid]-(x[i]-x[mid+1]);
while (ir>0 && a>=sr[ir-1].f)
{
ir--;
}
sr[ir].f=a;
sr[ir].s=i;
ir++;
}
for (int i=0;i<il;i++)
{
int flag=0;
for (int j=ir-1;j>=0;j--)
{
if (sl[i].f+sr[j].f>=x[mid+1]-x[mid])
{
ans=max(ans,sl[i].s==0 ? sumg[sr[j].s] : sumg[sr[j].s]-sumg[sl[i].s-1]);
flag=1;
break;
}
}
if (flag==0) break;
}
return ans;
}
int main()
{
cin>>n;
for (int i=0;i<n;i++)
{
scanf("%d%d%d",&x[i],&g[i],&e[i]);
if (i==0)
{
sumg[i]=g[i];
sume[i]=e[i];
}
else
{
sumg[i]=sumg[i-1]+g[i];
sume[i]=sume[i-1]+e[i];
}
}
cout<<solve(0,n-1)<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
7580 KB |
Output is correct |
2 |
Correct |
0 ms |
7580 KB |
Output is correct |
3 |
Correct |
0 ms |
7580 KB |
Output is correct |
4 |
Correct |
0 ms |
7580 KB |
Output is correct |
5 |
Correct |
0 ms |
7580 KB |
Output is correct |
6 |
Correct |
0 ms |
7580 KB |
Output is correct |
7 |
Correct |
0 ms |
7580 KB |
Output is correct |
8 |
Correct |
1 ms |
7580 KB |
Output is correct |
9 |
Correct |
0 ms |
7580 KB |
Output is correct |
10 |
Correct |
0 ms |
7580 KB |
Output is correct |
11 |
Correct |
0 ms |
7580 KB |
Output is correct |
12 |
Correct |
0 ms |
7580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
7580 KB |
Output is correct |
2 |
Correct |
0 ms |
7580 KB |
Output is correct |
3 |
Correct |
0 ms |
7580 KB |
Output is correct |
4 |
Correct |
0 ms |
7580 KB |
Output is correct |
5 |
Correct |
0 ms |
7580 KB |
Output is correct |
6 |
Correct |
4 ms |
7580 KB |
Output is correct |
7 |
Correct |
0 ms |
7580 KB |
Output is correct |
8 |
Correct |
0 ms |
7580 KB |
Output is correct |
9 |
Correct |
7 ms |
7580 KB |
Output is correct |
10 |
Correct |
8 ms |
7580 KB |
Output is correct |
11 |
Correct |
41 ms |
7580 KB |
Output is correct |
12 |
Correct |
41 ms |
7580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
7580 KB |
Output is correct |
2 |
Correct |
131 ms |
7580 KB |
Output is correct |
3 |
Correct |
162 ms |
7580 KB |
Output is correct |
4 |
Execution timed out |
1000 ms |
7576 KB |
Program timed out |
5 |
Halted |
0 ms |
0 KB |
- |