n stands arranged in a circle on a rotating platform. Stand i sells a candy for prices[i], and it starts out holding flavor i. The price belongs to the stand, not to the flavor.
For shift_cost you can rotate the candies: the flavor on stand i moves to stand (i + 1) mod n, for all stands at once. You may rotate as many times as you like and buy at any moment between rotations.
You need one candy of each of the n flavors. Return the minimum total spend: the prices of the candies you buy plus the cost of every rotation.prices=[9, 2, 8], shift_cost=3 → 12
Buy flavor 1 for 2. Turn (3): flavor 0 moves onto stand 1, buy it for 2. Turn again (3): flavor 2 is now on stand 1, pay 2 once more. Total 2 + 3 + 2 + 3 + 2 = 12, compared with 19 without turning.
prices=[4, 5, 6], shift_cost=10 → 15
Turning is too expensive, so just buy everything as is: 4 + 5 + 6 = 15.
prices=[9, 2, 8], shift_cost=3
12
Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.