1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| #include<bits/stdc++.h> using namespace std; #ifdef LOCAL #define debug(...) fprintf(stdout, ##__VA_ARGS__) #define debag(...) fprintf(stderr, ##__VA_ARGS__) #else #define debug(...) void(0) #define debag(...) void(0) #endif #define int long long inline int read(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back #define fi first #define se second
#define N 200010 struct node { int a, b, w; }a[N]; int n, m, i, j, k, T; int b[N], t, p, w, ans;
bool cmp(node x, node y) { if(x.a == y.a) return x.b < y.b; return x.a < y.a; }
struct Binary_tree { int cnt[N]; void add(int x, int k) { while(x < N) cnt[x] = max(cnt[x], k), x += x & -x; } int qry(int x) { int ans = 0; while(x) ans = max(ans, cnt[x]), x -= x & -x; return ans; } }Bin;
signed main() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif
n = read(); n = read(); for(i = 1; i <= n; ++i) { t = 2 * read(); p = read(); w = read(); a[i].a = t + p; a[i].b = t - p; a[i].w = w; b[i] = t - p; debug("[%lld %lld] ===> (%lld %lld)\n", t, p, a[i].a, a[i].b); } sort(a + 1, a + n + 1, cmp); sort(b + 1, b + n + 1); for(i = 1; i <= n; ++i) a[i].b = lower_bound(b + 1, b + n + 1, a[i].b) - b; for(i = 1; i <= n; ++i) { debug("%lld %lld | %lld\n", a[i].a, a[i].b, a[i].w); k = Bin.qry(a[i].b) + a[i].w; Bin.add(a[i].b, k); ans = max(ans, k); } printf("%lld", ans); return 0; }
|