Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Coins for Fruits

med
30 min
Try to solve the Minimum Number of Coins for Fruits problem.

Statement

You are given a 00 indexed integer array prices, where prices[i] represents the price of purchasing the (i+1)extth(i + 1)^{ ext{th}} fruit.

The market provides an offer: if you purchase the (i+1)extth(i + 1)^{ ext{th}} fruit for prices[i] coins, you are allowed to claim the next i+1i + 1 fruits for free. Subsequent fruits from index i+1i + 1 up to index 2⋅i+12 \cdot i + 1 can be taken at no cost.

Return the minimum number of coins needed to acquire all the fruits.

Note: You can choose to purchase a fruit even if you are eligible to take it for free, in order to activate its promotional reward.

Constraints:

  • 1≤1 \leq prices.length ≤1000\leq 1000

  • 1≤1 \leq prices[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Number of Coins for Fruits

med
30 min
Try to solve the Minimum Number of Coins for Fruits problem.

Statement

You are given a 00 indexed integer array prices, where prices[i] represents the price of purchasing the (i+1)extth(i + 1)^{ ext{th}} fruit.

The market provides an offer: if you purchase the (i+1)extth(i + 1)^{ ext{th}} fruit for prices[i] coins, you are allowed to claim the next i+1i + 1 fruits for free. Subsequent fruits from index i+1i + 1 up to index 2⋅i+12 \cdot i + 1 can be taken at no cost.

Return the minimum number of coins needed to acquire all the fruits.

Note: You can choose to purchase a fruit even if you are eligible to take it for free, in order to activate its promotional reward.

Constraints:

  • 1≤1 \leq prices.length ≤1000\leq 1000

  • 1≤1 \leq prices[i] ≤105\leq 10^5