Submission #363822

#TimeUsernameProblemLanguageResultExecution timeMemory
363822Sho10Divide and conquer (IZhO14_divide)C++17
100 / 100
39 ms7916 KiB
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10 #define ll long long #define double long double #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #define aint(a) (a).begin(), (a).end() #define f first #define s second #define pb push_back #define mp make_pair #define pi pair #define rc(s) return cout<<s,0 #define endl '\n' #define mod 1000000007 #define PI 3.14159265359 #define INF 1000000005 #define LINF 1000000000000000005ll #define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; ll n,pref[3][100005],x[100005],g[100005],d[100005],ans,mn[100005]; int32_t main(){ CODE_START; cin>>n; mn[0]=LINF; for(ll i=1;i<=n;i++) { cin>>x[i]>>g[i]>>d[i]; ans=max(ans,g[i]); pref[1][i]=pref[1][i-1]+g[i]; pref[2][i]=pref[2][i-1]+d[i]; mn[i]=min(mn[i-1],pref[2][i-1]-x[i]); } for(ll i=1;i<=n;i++) { ll l=1,r=i,res=i; while(l<=r){ ll mid=(l+r)/2; if(mn[mid]<=pref[2][i]-x[i]){ res=mid; r=mid-1; }else l=mid+1; } // cout<<pref[1][i]<<' '<<pref[1][res-1]<<' '; ans=max(ans,pref[1][i]-pref[1][res-1]); } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...