#include <bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
const int N = 2e5 + 10;
const int inf = 1e16 + 7;
int st[N * 4];
void Pull(int i) {
st[i] = max(st[i * 2], st[i * 2 + 1]);
}
void Update(int node, int tl, int tr, int i, int v) {
if(tl > i || tr < i) return;
if(tl == tr) {
st[node] = max(st[node], v);
return;
}
int mid = tl + tr >> 1;
Update(node * 2, tl, mid, i, v);
Update(node * 2 + 1, mid + 1, tr, i, v);
Pull(node);
}
int Query(int node, int tl, int tr, int l, int r) {
if(tl > r || tr < l) return -inf;
if(tl >= l && tr <= r) return st[node];
int mid = tl + tr >> 1;
return max(Query(node * 2, tl, mid, l, r), Query(node * 2 + 1, mid + 1, tr, l, r));
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> a(n + 1), b(n + 1);
vector<int> g[n + 1], f[n + 2];
for(int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
a[i] = i - a[i];
b[i] = i + b[i];
a[i] = max(a[i], 1ll);
b[i] = min(b[i], n);
g[i].push_back(a[i] - 1);
f[b[i] + 1].push_back(i);
}
vector<int> dp(n + 1, 1);
for(int i = 1; i <= n; i++) {
for(int j : f[i]) {
Update(1, 1, n, j, dp[j]);
}
for(int j : g[i]) {
dp[i] = max(dp[i], Query(1, 1, n, 1, j) + 1);
}
}
int ans = 0;
for(int i = 1; i <= n; i++) ans = max(ans, dp[i]);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |