25分
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
using namespace std;
int n, k, dp[5005][5005], a[5005][5005], ans, x, y;
int main(){
scanf("%d%d",&n,&k);
memset(dp, 0xA1, sizeof dp);
// cout<<dp[1][1]<<endl;
for(int i = 1; i <= n; i++){
scanf("%d%d",&x,&y);
a[x][y] = 1;
dp[x][y] = 1;
}
// cout<<dp[3][1]<<endl;
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++){
if(a[i][j]) {
dp[i][j] = max(dp[i][j], dp[i-1][j] + 1);
dp[i][j] = max(dp[i][j], dp[i][j-1] + 1);
// cout<<i<<" "<<j<<" "<<dp[i][j]<<endl;
}
ans = max(ans, dp[i][j]);
}
}
printf("%d\n",ans);
return 0;
}
// dp[x][y] = max(dp[x-1][y], dp[x][y-1]) + 1
#include<bits/stdc++.h>
using namespace std;
int n,m,dp[505][205],ans,c[505][505],rk,ri,rlt;
struct Node{
int x, y;
}a[505];
bool cmp(Node p, Node q){
if(p.x == q.x) return p.y < q.y;
return p.x < q.x;
}
int main(){
scanf("%d%d",&n,&m);
for(int i = 1; i <= n; i++){
scanf("%d%d",&a[i].x, &a[i].y);
}
sort(a+1, a+n+1, cmp);
for(int i = 1; i <= n; i++)
for(int j = 1; j < i; j++){
c[i][j] = abs(a[i].x - a[j].x) + abs(a[i].y - a[j].y) - 1;
}
for(int i = 1; i <= n; i++)
for(int k = 0; k <= m; k++) dp[i][k] = k+1;//非常重要的预处理,样例2,可以增加100个点
for(int i = 2; i <= n; i++){
for(int j = 1; j < i; j++){
for(int k = 0; k <= m; k++){//err: k = 0 开始 ,一个点也不增加的状态也会被已有的点更新,因此要从0开始
if(a[i].x >= a[j].x && a[i].y >= a[j].y && k >= c[i][j])
dp[i][k] = max(dp[i][k], dp[j][k - c[i][j]] + c[i][j] + 1);
}
}
}
for(int i=1;i<=n;i++)
ans=max(ans,dp[i][m]);
cout<<ans;
return 0;
}