#include #include using namespace std; using namespace atcoder; //using mint = modint1000000007; //const int mod = 1000000007; //using mint = modint998244353; //const int mod = 998244353; //const int INF = 1e9; const long long LINF = 1e18; #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep2(i,l,r)for(int i=(l);i<(r);++i) #define rrep(i, n) for (int i = (n-1); i >= 0; --i) #define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i) #define all(x) (x).begin(),(x).end() #define allR(x) (x).rbegin(),(x).rend() #define endl "\n" #define P pair template inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; } long long op(long long a, long long b) { return max(a, b); } long long e() { return -LINF; } map Compless(const vector &v) { vectorvv = v; sort(all(vv)); vv.erase(unique(all(vv)), vv.end()); mapmp; rep(i, vv.size()) mp[vv[i]] = i; return mp; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; vector>vec; vec.push_back({ {0 - 0,0 + 0},0 }); rep(i, n) { int t, x, v; cin >> t >> x >> v; if (t - x >= 0)vec.push_back({ {t - x,t + x},v }); } // vectortmp(vec.size()); rep(i, vec.size())tmp[i] = vec[i].first.second; sort(all(tmp)); tmp.erase(unique(all(tmp)), tmp.end()); // segtreeseg(tmp.size()); seg.set(lower_bound(all(tmp), 0) - tmp.begin(), 0); sort(all(vec)); rep(i, vec.size()) { int idx = lower_bound(all(tmp), vec[i].first.second) - tmp.begin(); long long get = seg.prod(0, idx + 1); if (-LINF == get)continue; seg.set(idx, get + vec[i].second); } cout << seg.all_prod() << endl; return 0; }