🎁 Exclusive Offer! Join our Telegram Channel to get **special discounts** and updates! 🚀

🚀 Struggling with coding interviews? We've got you covered! 💡 Practice real questions, sharpen your skills, and land your dream job! 🎯
Question 94 - 100% Working Solution | Buy Now

Description

10 Live
Remaining elements You are given two arrays A and B of size N. Your task is to remove some numbers from array A such that the following conditions are met: 1. The remaining elements of array A are strictly increasing from left to right. 2. The corresponding elements from B must also be extracted. For example, if you have removed the ith element of array A, then the ith element of array B must also be pulled out. Consider 1-based indexing. Find the maximum strength of the remaining elements of array B. Suppose the remaining elements of array B are Bn, Br2, ..., Bir, 1 ≤ I1, I2, ..., Ir < N, then the strength of array B is calculated as B1 - Bm + Bg - .... (-1)^r-1 * B. Note: 1-based indexing is followed. Input format: - The first line contains an integer T denoting the number of test cases. - The next line contains an integer N denoting the size. - The next two lines contain N space-separated integers denoting the elements of arrays A and B respectively. Output format: - Print the maximum strength of the remaining elements of array B in a new line. Constraints: - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 2 × 10^3 - 1 ≤ Ai, Bi ≤ 10^6 Sample input: 7 3 1 4 5 6 20 30 40 10 20 Sample output: 50 85

Asked in: GOOGLE

Image of the Question

Question Image Question Image Question Image Question Image Question Image

All Testcases Passed ✔



Passcode Image

Solution


Please login to view the solution