#include<bits/stdc++.h> #define MAX_N 10000 #define MAX_A 5500 #define MAX_M 500 usingnamespace std; template <classT> inlinevoidread(T &x){ x = 0; int c = getchar(), f = 1; for (; !isdigit(c); c = getchar()) if (c == 45) f = -1; for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0'); } int n, m, a[MAX_N+5], tr[MAX_M+5][MAX_A+5]; voidmodify(int p, int q, int c){ for (int i = p; i <= MAX_M+1; i += (i&-i)) for (int j = q; j <= MAX_A; j += (j&-j)) tr[i][j] = max(tr[i][j], c); } intquery(int p, int q){ int ret = 0; for (int i = p; i; i -= (i&-i)) for (int j = q; j; j -= (j&-j)) ret = max(ret, tr[i][j]); return ret; } intmain(){ read(n), read(m); int f, ans = 0; for (int i = 1; i <= n; i++) read(a[i]); for (int i = 1; i <= n; i++) for (int j = m; ~j; j--) ans = max(ans, f = query(j+1, a[i]+j)+1), modify(j+1, a[i]+j, f); returnprintf("%d\n", ans), 0; }