Collecting Chocolates
You are given a 0-indexed integer array nums of size n representing the cost of collecting different chocolates. The cost of collecting the chocolate at index i is nums[i]. Each chocolate is of a different type, and initially, the chocolate at index i is of i^th type.
In one operation, you can do the following with an incurred cost of x:
- Simultaneously change the chocolate of
i^thtype to((i + 1) mod n)^thtype for all chocolates.
Return the minimum cost to collect chocolates of all types, given that you can perform as many operations as you would like.
Example 1
Input
nums = [20,1,15], x = 5Output
13By buying one chocolate after each of two operations, the total cost is 1 + 5 + 1 + 5 + 1 = 13, which is optimal.
Example 2
Input
nums = [1,2,3], x = 4Output
6All three types can be collected at their own prices without performing any operations, for a total cost of 1 + 2 + 3 = 6.
Constraints
- 1 <= nums.length <= 1000
- 1 <= nums[i] <= 10^9
- 1 <= x <= 10^9