Given an array of integers, perform atmost K operations so that the sum of elements of final array is minimum. An operation is defined as follows - Consider any 1 element from the array, arr[i]. Replace arr[i] by floor(arr[i]/2). Perform next operations on updated array. The task is to minimize the sum after atmost K operations. code for above problem
Answers
Answered by
14
Answer:
a,b = input().strip().split(" ")
arr = list(map(int,input().strip().split(" ")))
b = int(b)
a = len(arr)
while b:
b=b-1
c=(max(arr)//2)
arr.remove(max(arr))
arr.append(c)
print(sum(arr))
Explanation:
You will get a presentation error, but dont worry
Similar questions
India Languages,
4 months ago
English,
8 months ago
Geography,
8 months ago
English,
11 months ago
Science,
11 months ago
Computer Science,
11 months ago