Answered step by step
Verified Expert Solution
Question
1 Approved Answer
can anyone solve this? help to write code in any language Problem Statement: Xavier's fight with Magneto has reached the final climax. The venues for
can anyone solve this? help to write code in any language
Problem Statement: Xavier's fight with Magneto has reached the final climax. The venues for war have been set up at X places. Xavier has N mutants who would be fighting for him, each having some power value. Since the war is going to be fought at X locations, he has to make X teams, each fighting at 1 venue. Each team would have K mutants where K=N/X. He is required to select special teams which will fight for him. Now, he knows Magneto's army is quite strong, so he has decided that each of his armies should-contain Mutants of different power values. Now, each individual army has a non-compatibility score which is equal Ito the difference between the maximum and minimum power value of mutants. He wants this score to be minimum. You need to help him divide the N mutants into X teams such that each team contains K mutants with different powers and returns the minimum non-compatibility score of the entire army Input Format: Line 1: N, the total number of mutants. Line 2: K, number of mutants which should be in an individual army. Line 3: Space separated array representing mutant's scores. Output Format: Print the minimum non-compatibility score of the entire army(sum of the non-compatibility score of all teams) which is formed following the above constraints. If the team can't be formed, then return -1 . Examples Example 1: Line 1: 12 Line 2: 4 Line 3:5,10,4,8,3,6,5,10,4,8,3,6 Output: 15 Explanation: Since there are 12 mutants and each team must have 4 mutants so he has to make 3 teams containing 4 mutants. The 3 teams would be as follows- (3,4,5,6) Non-Compatibility score =>63=3 (3,4,8,10) Non-Compatibility score =>103=7 (5,6,8,10) Non-Compatibility score =>105=5 So, the Non-compatibility score of the entire team would be (3+7+5)=15. Example 2: Line 1: 2 Line 2: 2 Line 3: 1, 1 Output: -1 Explanation: There are 2 mutants and each of them has the same power, and each team must have 2 mutants so he cannot make a team with 2 different mutants. The above-mentioned example is a sample test case for your understandingStep 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