#include<bits/stdc++.h> usingnamespace std; #ifdef LOCAL #define debug(...) fprintf(stdout, ##__VA_ARGS__) #else #define debug(...) void(0) #endif //#define int long long inlineintread(){int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+ (x<<3)+(ch^48);ch=getchar();}return x*f;} #define Z(x) (x)*(x) #define pb push_back #define fi first #define se second #define M 510 //#define mo #define N 5510 int n, m, i, j, k, T; int ans, x, a[10010];
structBin1 { int cnt[N]; intqry(int x){ ++x; int ans = 0; while(x) ans = max(ans, cnt[x]), x -= x & -x; return ans; } voidadd(int x, int k){ ++x; while(x < N) cnt[x] = max(cnt[x], k), x += x & -x; } }B1[M];
structBin2 { int cnt[M]; intqry(int x){ int ans = 0; ++x; while(x) ans = max(ans, cnt[x]), x -= x & -x; return ans; } voidadd(int x, int k){ ++x; while(x < M) cnt[x] = max(cnt[x], k), x += x & -x; } }B2[N];
signedmain() { #ifdef LOCAL freopen("in.txt", "r", stdin); freopen("out.txt", "w", stdout); #endif // srand(time(NULL)); // T=read(); // while(T--) { // // } n = read(); m = read(); for(i = 1; i <= n; ++i) a[i] = read(); for(i = 1; i <= n; ++i) { x = 0; for(k = 0; k <= m; ++k) { x = max({x, B1[k].qry(a[i] + k), B2[a[i] + k].qry(k)}); B1[k].add(a[i] + k, x + 1); B2[a[i] + k].add(k, x + 1); ans = max(ans, x + 1); } } printf("%d", ans); return0; }