#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> l(n + 1), r(n + 1); // 1-indexed
for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];
vector<int> dp(n + 1, 1); // dp[i] = 1 initially
int ans = 1;
for (int i = 2; i <= n; i++) {
int left_ignore = l[i];
int start = max(1, i - 5); // limit the search to last 5 tulips
int end = i - left_ignore - 1;
for (int j = start; j <= end; j++) {
if (j + r[j] < i) { // if picking j does not block i
dp[i] = max(dp[i], dp[j] + 1);
}
}
ans = max(ans, dp[i]);
}
cout << ans;
return 0;
}
| # | 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... |