Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Thanos, in his mission to restore the ecological balance in the universe, has reached planet earth. He considers a planet ecologically balanced if more than
Thanos, in his mission to restore the ecological balance in the universe, has reached planet earth. He considers a planet ecologically balanced if more than half of the people on the planet have the same Consumption Capacity. There are Npeople on planet earth, each having Consumption Capacity C1,C2, ...,CNand StrengthS1,S2, ...,SN. Thanos will make earth ecological balanced by killing some people(Possibly None). To kill a person with StrengthK, Thanos spendsKunits of his energy. Thanos, being a conservationist, wants to spend as less energy as possible in the process. Help him determine the minimum energy he should spend to make earth ecologically balanced. Input: First line of input contains a single integerNdenoting the number of people on planet Earth.The second line containsNspace separated integersC1,C2, . . . ,CNdenoting the Consumption Capacity of theithperson.The third line contains Nspace separated integersS1,S2, . . . ,SNdenoting the Strength of the ithperson. Output: Output a single integer denoting the minimum energy Thanos spends. Constraints 1N210^5 1Ci10^6 1Si10^9 Sample Input 1: 1 5 10 Sample Output 1: 0 EXPLANATION: Thanos won't kill anyone as the planet is already ecologically balanced. Hence energy spent = 0. Sample Input 2: 2 5 8 4 2 Sample Output 2: 2 Sample Input 3: 7 2 2 1 1 1 3 3 20 30 2 5 3 15 3 Sample Output 3: 13
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