Submission #1040337

#TimeUsernameProblemLanguageResultExecution timeMemory
1040337vjudge1Divide and conquer (IZhO14_divide)C++17
100 / 100
18 ms7384 KiB
#include<bits/stdc++.h> #define INF 1e18 #define fi first #define se second #define FOR(i, k, n) for(ll i = k; i <= n; i++) #define FOR1(i, k, n) for(ll i = k; i >= n; i--) #define pb push_back #define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0) #define vi vector<int> #define pii pair<int, int> #define vii vector<pii> #define ll long long #define vll vector<ll> #define pll pair<ll, ll> #define re return 0 #define mii map<int, int> #define input "BAI1.inp" #define output "BAI1.out" #define rf freopen(input, "r", stdin); freopen(output, "w", stdout) using namespace std; const int maxn = 1e5 + 5; const int mod = 1e9 + 7; ll f[maxn], f1[maxn]; ll T[maxn * 4]; struct shape{ int x, g, d; }; shape a[maxn]; int main() { fastio; int n; cin >> n; FOR(i, 1, n) { cin >> a[i].x >> a[i].g >> a[i].d; } vii v; ll ans = a[1].g; v.pb({- a[1].x, 1}); f[1] = a[1].d; f1[1] = a[1].g; FOR(i, 2, n) { ans = max(ans, (ll)a[i].g); f1[i] = f1[i - 1] + a[i].g; f[i] = f[i - 1] + a[i].d; ll res = f[i] - a[i].x; ll t = f[i - 1] - a[i].x; if(t < v.back().fi) v.pb({t, i}); int l = 0, r = v.size() - 1, vt = -1; while(l <= r) { int mid = (l + r) >> 1; if(v[mid].fi <= res) { vt = mid; r = mid - 1; } else l = mid + 1; } if(vt != -1) { vt = v[vt].se; ans = max(ans, f1[i] - f1[vt - 1]); } res = f[i - 1] - a[i].x; } cout << ans; re; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...