Minimum Total Weight

There are n chocolates and the weight of the chocolates is given as an array of integers weights[n], where weights[i] denote the weight of the ith chocolate. Every day, one can pick one chocolate, eat half of it, and put the remaining half back. Find the minimum possible total weight of the remaining chocolates after d days. Note that one can eat the same chocolate multiple times. The weight of the part eaten can be calculated as floor(weights[i]/2).

Function Description

Complete the function findMinWeight in the editor below.

findMinWeight has the following parameters:

  1. int weights[n]: an array of integers representing weights of chocolates, indexed 0 to n-1
  2. int d: an integer representing the number of days

Returns

int: the minimum total weight of chocolates after d days.

\U0001fae7A heartfelt thank you to A ⋆°

Constraints:

  • 1 ≤ n ≤ 10^5
  • 1 ≤ weights[i] ≤ 10^4 (where 0 ≤ i < n)
  • 1 ≤ d ≤ 2*10^6

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: