Submission #528791

#TimeUsernameProblemLanguageResultExecution timeMemory
528791perchutsDivide and conquer (IZhO14_divide)C++17
17 / 100
1 ms332 KiB
#include <bits/stdc++.h> #define maxn (int)(1e5+51) #define all(x) x.begin(), x.end() #define sz(x) (int) x.size() #define endl '\n' #define ll long long #define pb push_back #define ull unsigned long long #define ii pair<int,int> #define iii tuple<int,int,int> #define inf 2000000001 #define mod 1000000007 //998244353 #define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; } template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; } struct mine{ ll x,g,e; }; mine v[maxn]; ll pref[maxn]; int bit[maxn],n; void insert(int x,int d){ for(;x<=n+100;x+=x&(-x))ckmin(bit[x],d); } int query(int x){ int ans = inf; while(x){ ckmin(ans,bit[x]); x -= x&(-x); } return ans; } int main(){_ cin>>n; for(int i=1;i<=n;++i){ cin>>v[i].x>>v[i].g>>v[i].e; bit[i] = inf; } vector<ll>cmp; ll sum = v[1].e; pref[1] = v[1].g; for(int i=2;i<=n;++i){ sum -= abs(v[i-1].x - v[i].x); cmp.pb(sum); sum += v[i].e; pref[i] = pref[i-1] + v[i].g; } cmp.pb(0); sort(all(cmp)); // for(auto x:cmp)cout<<x<<" "; // cout<<endl; // for(int i=1;i<=n;++i)cout<<pref[i]<<" "; // cout<<endl; // S - S' >= 0 => S >= S' sum = v[1].e; int ans = 0; for(int i=1;i<=n;++i){ if(i!=1)sum += v[i].e - abs(v[i].x - v[i-1].x); int ind = lower_bound(all(cmp),sum) - begin(cmp) + 1; if(ind!=n+1&&cmp[ind-1]>sum)ind--; int q = min(i,query(ind)); ckmax(ans,pref[i]-pref[q-1]); int ind2 = lower_bound(all(cmp),sum-v[i].e) - begin(cmp) + 1; insert(ind2,i); } // cout<<endl; cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...