#include <bits/stdc++.h>
using namespace std;
struct Fenwick {
int n;
vector<int> bit;
Fenwick(int n) {
this->n = n;
bit = vector<int>(n + 2);
}
void update(int i, int delta) {
i++;
for (; i <= n + 1; i += i & -i) {
bit[i] = max(bit[i], delta);
}
}
int query(int i) {
int res = 0;
i++;
for (; i > 0; i -= i & -i) {
res = max(res, bit[i]);
}
return res;
}
};
int main() {
int n;
cin >> n;
vector<int> l(n + 1), r(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> l[i] >> r[i];
}
vector<vector<int>> dp(n + 1, vector<int>(n + 1));
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
dp[i][j] = dp[i - 1][j];
}
int left = max(0, i - l[i] - 1);
for (int j = 0; j <= left; ++j) {
int right = j + r[j] + 1;
if (i >= right) {
dp[i][i] = max(dp[i][i], dp[i - 1][j] + 1);
}
}
}
int res = 0;
for (int i = 0; i <= n; ++i) {
res = max(res, dp[n][i]);
}
cout << res << "\n";
}
# | 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... |