Submission #1123768

#TimeUsernameProblemLanguageResultExecution timeMemory
1123768IcelastDivide and conquer (IZhO14_divide)C++17
100 / 100
52 ms9176 KiB
#include <iostream> #include <bits/stdc++.h> #define ll long long using namespace std; const ll maxn = 2*1e5+5, INF = 4e18+9; struct mine{ ll x, g, d; }; struct normalize{ vector<ll> poi, pot; void add(ll x){ poi.push_back(x); } void start(){ sort(poi.begin(), poi.end()); if(poi.size() > 0) pot.push_back(poi[0]); for(int i = 1; i < (int)poi.size(); i++){ if(poi[i] != poi[i-1]){ pot.push_back(poi[i]); } } } int encode(ll x){ return lower_bound(pot.begin(), pot.end(), x) - pot.begin()+1; } }; template <class T> struct Fenwick { int n, log; vector<T> bit; Fenwick(int n) : n(n), log(32 - __builtin_clz(n + 1)), bit(n + 1, INF) {} void add(int i, T delta) { for (; i <= n; i += i & -i) { bit[i] = min(bit[i], delta); } } T get(int i) { T res = INF; for (; i > 0; i -= i & -i) { res = min(res, bit[i]); } return res; } }; void solve(){ int n; cin >> n; vector<mine> a(n+1); for(int i = 1; i <= n; i++){ cin >> a[i].x >> a[i].g >> a[i].d; } sort(a.begin()+1, a.end(), [&](mine a, mine b){return a.x < b.x;}); vector<ll> pfd(n+1, 0), pfg(n+1, 0); normalize norm; for(int i = 1; i <= n; i++){ pfd[i] = pfd[i-1]+a[i].d; pfg[i] = pfg[i-1]+a[i].g; norm.add(pfd[i]-a[i].x); norm.add(pfd[i-1]-a[i].x); } norm.start(); ll ans = 0; int N = norm.pot.size(); Fenwick<ll> bit(N+1); for(int i = 1; i <= n; i++){ bit.add(norm.encode(pfd[i-1]-a[i].x), pfg[i-1]); ll val = pfg[i] - bit.get(norm.encode(pfd[i]-a[i].x)); ans = max(ans, val); } cout << ans; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...