GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Wednesday, 27 April 2022

Three Arrays CodeChef Solution | CodeChef Problem Solution 2022

You are given three arrays AB, and C, all of length N. You also have two integers k1 and k2.

For every index 1iN, you must choose exactly one of Ai,Bi, or Ci. Find the maximum possible sum of chosen elements, such that:

  • At most k1 elements are picked from A, and
  • At most k2 elements are picked from B

Input Format

  • The first line of input contains an integer T, denoting the number of test cases. T test cases follow.
  • Each test case consists of five lines of input.
Solution Click Below:- 

  • The first line of each test case contains the integer N — the length of the arrays.
  • The second line contains N space-separated integers A1,A2,,AN.
  • The third line contains N space-separated integers B1,B2,,BN.
  • The fourth line contains N space-separated integers C1,C2,,CN.
  • The fifth line contains two space-separated integers k1 and k2.

Output Format

For each test case, output on a new line the maximum sum possible by selecting the elements under the specified constraints.

Constraints

  • 1T105
  • 1N5105
  • 1Ai,Bi,Ci109
  • 0k1,k2N
  • It is guaranteed that the sum of N across all test cases doesn't exceed 5105.

Sample Input 1 

2
4
10 4 8 5
9 7 6 6
5 5 7 11
2 1
5
12 44 32 12 32
43 32 12 32 31
34 12 43 23 41
3 4

Sample Output 1 

36
203

Explanation

Test case 1: Choose A1=10,B2=7,A3=8 and C4=11, for a sum of 36.

Test case 2: Choose B1=43,A2=44,C3=43,B4=32,C5=41, for a sum of 203.

Join Now for Solution:- 

No comments:

Post a Comment