You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
828 B

#include <bits/stdc++.h>
const int N = 510;
using namespace std;
int n, m, ans;
int f[N][N];
struct Node {
int x, y;
const bool operator<(const Node &t) const {
if (x == t.x) return y < t.y;
return x < t.x;
}
} a[N];
int dfs(int u, int r) {
if (f[u][r]) return f[u][r];
int ans = r + 1;
for (int i = u + 1; i <= n; i++) {
if (a[i].y < a[u].y) continue;
int d = a[i].x - a[u].x + a[i].y - a[u].y - 1;
if (d > r) continue;
ans = max(ans, dfs(i, r - d) + d + 1);
}
return f[u][r] = ans;
}
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i].x >> a[i].y;
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) ans = max(ans, dfs(i, m));
printf("%d\n", ans);
return 0;
}