Unable to get AC

I’ve submitted the exact code as described in the Coding video but still unable to get AC. Please tell me where I’m wrong.

hello @rishabhtyagi.2306
pls share ur code using cb ide

@aman212yadav Here is the link to my code.

@rishabhtyagi.2306
once try to submit ur code here and let me know what verdict u r getting

@aman212yadav it is giving TLE on Leet Code. And wrong answer on coding blocks

try dp . because of too many for loops it exceeded the time limit.

class Solution {
public:
    int longestArithSeqLength(vector<int>& A) {
        int n=A.size();
        vector< vector<int> > dp(n,vector<int>(1005,0));
        int ans=0;
        for(int i=0;i<n;i++){
            
            for(int j=0;j<i;j++){
                int diff=A[i]-A[j]+500;
                int &x=dp[i][diff],&y=dp[j][diff];
                x=max(x,1+y);
                ans=max(ans,1+x);
            }
        }
        return ans;
    }
};

dp state is simple.
dp[i][diff] =longest ap when array [0…i] is considered and common difference is diff

@aman212yadav The dp code works well on leet code but giving WA on Coding blocks.

its becuase of input format, there are more than one test cases in input file.