Submission #528813

#TimeUsernameProblemLanguageResultExecution timeMemory
528813perchutsDivide and conquer (IZhO14_divide)C++17
48 / 100
52 ms7624 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; } for(int i=0;i<=n+100;++i)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)); cmp.erase(unique(all(cmp)),cmp.end()); // for(auto x:cmp)cout<<x<<" "; // cout<<endl; // for(int i=1;i<=n;++i)cout<<pref[i]<<" "; // cout<<endl; sum = v[1].e; ll 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!=sz(cmp)+1&&cmp[ind-1]>sum)ind--; // cout<<ind<<" "<<sum<<endl; 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...