Submission #1128131

#TimeUsernameProblemLanguageResultExecution timeMemory
1128131MrPavlitoDivide and conquer (IZhO14_divide)C++20
0 / 100
2 ms3396 KiB
#include <bits/stdc++.h> #define int long long #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define sc second #define endl "\n" #define pii pair<int,int> using namespace std; const int MAXN = 1e5+5; const int mod7 = 1e9+7; const long long inf = 1e18; struct rudnik{int x,g,d;}; vector<int> seg(MAXN<<2, -inf); void update(int nod, int tl, int tr, int index, int v) { if(tl == tr) { seg[nod] = v; return; } int mid = tl+tr>>1; if(index<=mid)update(nod<<1, tl, mid, index, v); else update(nod<<1|1, mid+1, tr, index, v); seg[nod] = max(seg[nod<<1], seg[nod<<1|1]); } int get(int nod, int tl, int tr, int v) { if(tl == tr)return tl; int mid = tl+tr>>1; if(seg[nod<<1|1] >= v)return get(nod<<1|1, mid+1, tr, v); else if(seg[nod<<1] >= v)return get(nod<<1, tl, mid, v); return -1; } signed main() { ios_base::sync_with_stdio(false),cin.tie(0), cout.tie(0); int tt=1; //cin >> tt; while(tt--) { int n; cin >> n; vector<rudnik>svi(n); int mx = 0; for(int i=0; i<n; i++)cin >> svi[i].x >> svi[i].g >> svi[i].d, mx = max(mx, svi[i].g); vector<int> prefd(n+1, 0); vector<int> prefg(n+1, 0); for(int i=0; i<n; i++)prefd[i+1] = prefd[i] + svi[i].d; for(int i=0; i<n; i++)prefg[i+1] = prefg[i] + svi[i].g; for(int i = 0;i<n; i++) { int tr = svi[i].x - prefd[i+1]; int index = get(1,1,n, tr); if(index != -1)mx = max(mx, prefg[i+1] - prefg[index-1]); update(1,1,n,i+1,svi[i].x - prefd[i]); } cout << mx << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...