Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A shopkeeper sells n items where the price of theith item is price [ i ] . To maintain balance, theshopkeeper wishes to adjust the
A shopkeeper sells n items where the price of theith item is pricei To maintain balance, theshopkeeper wishes to adjust the price of itemssuch that the mediag of prices is exactly k In onemove, the shopkeeper can increase or decrease theprice of any item by and the shopkeeper canperform this move any number of timesVCFind the minimum number of moves in which themedian of prices becomes exactly kNote: The index of the median of an array ofm sorted elements, where mis odd, is m Forexample, sorted is lts length is so the median is at index using based indexing. The median is ExampleConsider n price and kDecrease price by the resulting array is on sorting, this becomes whosemedian equals k Thus, in one move, themedian becomes and the answer is
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