제출 #1130396

#제출 시각아이디문제언어결과실행 시간메모리
1130396zhasyn금 캐기 (IZhO14_divide)C++20
100 / 100
103 ms4240 KiB
#include <bits/stdc++.h> #define pb push_back #define pf push_front using namespace std; #define F first #define S second typedef long long ll; #define pii pair <int, int> #define pll pair <ll, ll> typedef long double ld; const ll N = 1e5 + 100, M = 500 + 10, len = 315, inf = 1e18; const ll mod = 998244353; ll um(ll a, ll b){ return (1LL * a * b) % mod; } ll subr(ll a, ll b){ return ((1LL * a - b) % mod + mod) % mod; } ll bp(ll x, ll step){ ll res = 1; while(step){ if(step & 1) res = um(res, x); x = um(x, x); step /= 2; } return res; } ll inv(ll x){ return bp(x, mod - 2); } ll p[N], g[N], e[N], mx; void calc(ll l, ll r){ if(r - l == 0) return; if(r - l == 1){ mx = max(mx, g[l]); return; } ll mid = (r + l) / 2; calc(l, mid); calc(mid, r); vector <pll> st; ll dis, gold = 0, en = 0; for(ll i = mid - 1; i >= l; i--){ dis = p[mid] - p[i]; gold += g[i]; en += e[i]; while((ll)st.size() != 0){ pll v = st.back(); if(dis - en <= v.S) st.pop_back(); else break; } st.pb({gold, dis - en}); } // cout << l << " "<< r << " Here\n"; // for(auto u : st){ // cout << u.F << " "<< u.S << endl; // } // cout << endl; en = gold = 0; for(ll i = mid; i < r; i++){ dis = p[i] - p[mid]; en += e[i]; gold += g[i]; ll lx = 0, rx = (ll)st.size(); while(rx - lx > 1){ ll midx = (lx + rx) / 2; if(st[midx].S <= en - dis) lx = midx; else rx = midx; } if(en - dis >= st[lx].S){ mx = max(mx, st[lx].F + gold); } } } int main() { //ios_base::sync_with_stdio(false); //cin.tie(nullptr); //cout.tie(nullptr); ll n; cin >> n; for(ll i = 0; i < n; i++){ cin >> p[i] >> g[i] >> e[i]; } calc(0, n); cout << mx; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...