This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5;
const ll inf=1e18;
const ll mod=1e9+7;
ll ans=-inf;
ll n,x[maxN],g[maxN],d[maxN],pre[maxN],pre2[maxN],mn[maxN];
void solve()
{
cin >> n;
for(int i=1;i<=n;i++) cin >> x[i] >> g[i] >> d[i],pre[i]=pre[i-1]+d[i],pre2[i]=pre2[i-1]+g[i];
for(int i=1;i<=n;i++)
{
ll sum=g[i],re=d[i];
ans=max(ans,sum);
}
mn[n+1]=-inf;
for(int i=n;i>=1;i--)
{
mn[i]=max(mn[i+1],pre[i]-x[i]);
}
for(int i=1;i<n;i++)
{
ll low=i+1,high=n;
while(low<=high)
{
ll mid=low+high>>1;
if(mn[mid]>=pre[i-1]-x[i]) low=mid+1;
else high=mid-1;
}
ans=max(ans,pre2[high]-pre2[i-1]);
}
cout << ans;
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message (stderr)
divide.cpp: In function 'void solve()':
divide.cpp:21:21: warning: unused variable 're' [-Wunused-variable]
21 | ll sum=g[i],re=d[i];
| ^~
divide.cpp:34:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | ll mid=low+high>>1;
| ~~~^~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |