#include #include typedef struct { long long key; int id; } data; void merge_sort(int n, data x[]) { static data y[200001] = {}; if (n <= 1) return; merge_sort(n / 2, &(x[0])); merge_sort((n + 1) / 2, &(x[n/2])); int i, p, q; for (i = 0, p = 0, q = n / 2; i < n; i++) { if (p >= n / 2) y[i] = x[q++]; else if (q >= n) y[i] = x[p++]; else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++]; } for (i = 0; i < n; i++) x[i] = y[i]; } void chmax(long long* a, long long b) { if (*a < b) *a = b; } void update_BIT(int N, long long BIT[], int i, long long k) { while (i <= N) { chmax(&(BIT[i]), k); i += (i & -i); } } long long max_BIT(long long BIT[], int r) { long long max = 0; while (r > 0) { chmax(&max, BIT[r]); r -= (r & -r); } return max; } int main() { int i, N, T[200001], Z[200001], V[200001], X[200001], Y[200001]; data d[2][200001]; scanf("%d", &N); for (i = 1, X[0] = 0, Y[0] = 0, d[0][0].key = 0, d[0][0].id = 0, d[1][0].key = 0, d[1][0].id = 0; i <= N; i++) { scanf("%d %d %d", &(T[i]), &(Z[i]), &(V[i])); if (abs(Z[i]) > T[i]) { i--; N--; continue; } X[i] = T[i] + Z[i]; Y[i] = T[i] - Z[i]; d[0][i].key = X[i]; d[0][i].id = i; d[1][i].key = Y[i]; d[1][i].id = i; } merge_sort(N + 1, d[0]); merge_sort(N + 1, d[1]); int j, n, m, x[200003], y[200003]; for (i = 0, n = 0; i <= N; i = j) { x[++n] = d[0][i].key; for (j = i; j <= N && d[0][j].key == x[n]; j++) X[d[0][j].id] = n; } for (i = 0, m = 0; i <= N; i = j) { y[++m] = d[1][i].key; for (j = i; j <= N && d[1][j].key == y[m]; j++) Y[d[1][j].id] = m; } long long BIT[200003] = {}; for (i = 1; i <= N; i++) { d[0][i-1].key = ((long long)X[i] << 20) + Y[i]; d[0][i-1].id = i; } merge_sort(N, d[0]); for (i = 0; i < N; i++) { j = d[0][i].id; update_BIT(m, BIT, Y[j], max_BIT(BIT, Y[j]) + V[j]); } printf("%lld\n", max_BIT(BIT, m)); fflush(stdout); return 0; }