Submission #719114

#TimeUsernameProblemLanguageResultExecution timeMemory
719114fdnfksdDivide and conquer (IZhO14_divide)C++14
100 / 100
45 ms8048 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...