Untitled

mail@pastecode.io avatar
unknown
plain_text
7 days ago
499 B
3
Indexable
Never
int findAns(int index, int lastIndex,vector<int> A, vector<int> B, int K, int N, int Y)
{
    if(index<0|| K == 0)
        return 0;
    int pick = INT_MIN;

    if(lastIndex == N || abs(A[index]- A[lastIndex])<=Y)
     pick = B[index] + findAns(index-1,index,A,B,K-1,N,Y);
     int notPick = findAns(index-1,lastIndex,A,B,K,N,Y);

     return max(pick,notPick);
        


}
int get_ans(int N, int K, int Y, vector<int> A, vector<int> B)
{
    return findAns(N-1,N,A,B,K,N,Y);

}
Leave a Comment