k ordered lcsquestion

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll dp[2001][2001][2001];
ll check(ll a[],ll b[],ll n,ll m,ll k)
{ if(k<0)
return -1e7;
if(n<0||m<0)
return 0;
if(dp[n][m][k]!=-1)
return dp[n][m][k];
dp[n][m][k]=max(check(a,b,n-1,m,k),check(a,b,n,m-1,k));
if(a[n]==b[m])
dp[n][m][k]=max(dp[n][m][k],1+check(a,b,n-1,m-1,k));
dp[n][m][k]=max(dp[n][m][k],1+check(a,b,n-1,m-1,k-1));
return dp[n][m][k];
}

int main()
{
ll n,m,s;
cin>>n>>m>>s;
ll a[n];
ll b[m];
for(ll i=0;i<n;i++)
cin>>a[i];
for(ll j=0;j<n;j++)
cin>>b[j];
memset(dp,-1,sizeof(dp));
// for(int i=0;i<n;i++)
// for(int j=0;j<m;j++)
// for(int k=0;k<s;k++)
// cout<<dp[i][j][k]<<" ";
cout<<check(a,b,n,m,s);
return 0;
}

Heyy ! you have created a 3d array of size 200120012001 which is ~~ 10^9 . You are not supposed to create an array of size more than ~ 10^8 . if you see here carefully , range of k is much smaller than 2001 so you can replace the range for k that you have wriitten here with 10. .