#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define st string
#define fr first
#define se second
const ll mod=1e9+7;
using namespace std;
ll p[100100], s[100100], n, ans=0, a[100100];
bool divide(ll x)
{
ll l=1, r=1;
while(a[r+1]-a[l]<=x && r+1<=n)
r++;
ll k=0;
//cout<<x<<" "<<l<<" "<<r<<endl;
while(l<=n)
{
while(a[r+1]-a[l]<=x && r+1<=n)
r++;
//cout<<x<<" "<<l<<" "<<r<<endl;
ll ener=p[r]-p[l-1];
if(ener>=x)
{
k++;
ll gold=s[r]-s[l-1];
ans=max(ans, gold);
}
l++;
}
if(k) return true;
else return false;
}
int main()
{
//freopen("1.txt", "r", stdin);
//freopen("1.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(ll i=1; i<=n; i++)
{
ll g, e;
cin>>a[i]>>g>>e;
p[i]=e+p[i-1];
s[i]=g+s[i-1];
}
ll l=0, r=1e9+1;
while(l+1<r)
{
//cout<<l<<" "<<r<<endl;
ll d=(l+r)/2;
if(divide(d)) l=d;
else r=d;
}
//cout<<l<<" "<<r<<endl;
cout<<ans;
return 0;
}
/*
4 6 3
1 2 1
2 4 1
2 3 2
3 1 4
1 4 3
3 4 10
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Incorrect |
2 ms |
588 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
696 KB |
Output is correct |
2 |
Correct |
5 ms |
1016 KB |
Output is correct |
3 |
Correct |
6 ms |
1168 KB |
Output is correct |
4 |
Correct |
21 ms |
2720 KB |
Output is correct |
5 |
Correct |
23 ms |
2728 KB |
Output is correct |
6 |
Correct |
46 ms |
4024 KB |
Output is correct |
7 |
Correct |
40 ms |
4024 KB |
Output is correct |
8 |
Correct |
40 ms |
4024 KB |
Output is correct |
9 |
Correct |
34 ms |
4024 KB |
Output is correct |
10 |
Correct |
54 ms |
4024 KB |
Output is correct |
11 |
Incorrect |
54 ms |
4024 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |