C++#include<bits/stdc++.h>
using namespace std;
struct node{
int x,y;
};
//n已有点数量 k可添加点数量
int n,k;
node a[510];
bool cmp(node a, node b) {
if (a.x == b.x) {
return a.y < b.y;
}
return a.x < b.x;
}
int dp[510][510];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i].x >> a[i].y;
}
int ans = 0;
sort(a + 1, a + 1 + n, cmp);
for (int i = 0; i <= k; i++) {
for (int j = 1; j <= n; j++) {
dp[i][j] = 1 + i;
for (int l = 1; l < j; l++) {
if (a[l].x <= a[j].x && a[l].y <= a[j].y) {
int t = a[j].x - a[l].x + a[j].y - a[l].y - 1;
if (t <= i) {
dp[i][j] = max(dp[i][j], dp[i - t][l] + t + 1);
}
}
}
ans = max(ans, dp[i][j]);
}
}
cout << ans;
}