#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int ll;
struct camp {
int x,g,d;
};
vector<camp> v;
const int N=1e6+7;
ll p[N];
ll sum[N];
ll lol[N];
int main()
{
ios_base:: sync_with_stdio(false); cin.tie(0);
int n; cin>>n;
v.resize(n+1);
for(int i=1; i<=n; i++) {
cin>>v[i].x>>v[i].g>>v[i].d;
p[i]=p[i-1]+v[i].d;
sum[i]=sum[i-1]+v[i].g;
lol[i]=p[i]-v[i].x;
}
/*
for(int i=1; i<=n; i++) {
cout<<i<<" "<<lol[i]<<endl;
}
*/
for(int i=n-1; i>=1; i--) {
lol[i]=max(lol[i],lol[i+1]);
}
// v[j].x-v[i].x<=p[j]-p[i-1]
// p[i-1]-v[i].x<=p[j]-v[j].x
ll ans=0;
for(int i=1; i<=n; i++) {
int me=p[i-1]-v[i].x;
int l=i;
int r=n;
ans=max(ans,sum[i]-sum[i-1]);
while(l<=r) {
int mid=(l+r)/2;
if(lol[mid]>=me) {
ans=max(ans,sum[mid]-sum[i-1]);
l=mid+1;
}
else{
r=mid-1;
}
}
}
cout<<ans<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
512 KB |
Output is correct |
7 |
Correct |
2 ms |
444 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
4 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
896 KB |
Output is correct |
3 |
Correct |
5 ms |
896 KB |
Output is correct |
4 |
Correct |
20 ms |
3200 KB |
Output is correct |
5 |
Correct |
21 ms |
3584 KB |
Output is correct |
6 |
Correct |
44 ms |
6904 KB |
Output is correct |
7 |
Correct |
34 ms |
5752 KB |
Output is correct |
8 |
Correct |
37 ms |
5880 KB |
Output is correct |
9 |
Correct |
33 ms |
5624 KB |
Output is correct |
10 |
Correct |
34 ms |
5624 KB |
Output is correct |
11 |
Correct |
38 ms |
6136 KB |
Output is correct |
12 |
Correct |
37 ms |
6264 KB |
Output is correct |