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>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const ll inf = 1e9;
const int mxn = 1e5+10;
int N;
array<ll,3> arr[mxn];
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N;
for(int i = 1;i<=N;i++){
cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
arr[i][1] += arr[i-1][1];
arr[i][2] += arr[i-1][2];
}
ll ans = 0;
vector<pll> v;
for(int i = 1;i<=N;i++){
if(v.empty()||v.back().fs>arr[i-1][2]-(arr[i][0]))v.push_back(pll(arr[i-1][2]-(arr[i][0]),i));
auto it = lower_bound(v.rbegin(),v.rend(),pll(arr[i][2]-arr[i][0],inf));
if(it != v.rbegin()){
it--;
ans = max(ans,arr[i][1]-arr[it->sc-1][1]);
}
}
cout<<ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |