Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ Language You are given two sequences dj, d2, ... , an and b1,b2, . bn. Each element of both sequences is either 0, 1
C++ Language
You are given two sequences dj, d2, ... , an and b1,b2, . bn. Each element of both sequences is either 0, 1 or 2. The number of elements 0, 1, 2 in the sequence a is x1, yi, z respectively, and the number of elements 0, 1, 2 in the sequence b is X2, Y2, z2 respectively. You can rearrange the elements in both sequences a and b however you like. After that, let's define a sequence c as follows: a;b; if a; > bi Ci = 30 if a; = b; -a;b; if a; 0) the number of 0-s, 1-s and 2-s in the sequenceb. Output For each test case, print the maximum possible sum of the sequence c. Example Input 3 2 3 2 3 3 1 4 0 1 2 3 0 0 0 1 0 0 1 Output 4 Na Note In the first sample, one of the optimal solutions is: a = {2,0, 1, 1,0, 2, 1} b = {1,0,1,0, 2, 1,0} C = {2,0,0,0,0,2,0} In the second sample, one of the optimal solutions is: a = {0,2,0,0,0} b = {1, 1, 0, 1,0} C= {0,2,0,0,0} In the third sample, the only possible solution is: a = {2} b = {2} c = {0}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started