Janet has N bags in a row. Each bag has a weight (Wi). Janet can collect bags from either the leftmost or rightmost position, but there are energy costs:
Wi) multiplied by X (if collecting from the left) or Y (if collecting from the right).El (if collected from the left side consecutively) or Er (if collected from the right side consecutively).Find the strategy that minimizes the total energy cost Janet spends to collect all the bags and display the minimum cost Bob has to pay.
Input Format
The first line of input contains five space-separated integers: N (number of bags), X, Y, El, Er (energy costs)
The second line of input contains N space-separated integers representing the weight of each bag (Wi).
Output Format
Display the minimum energy cost expenditure for Bob.
Examples
01 · Example 1
weights = [42, 3, 99] X = 4 Y = 4 El = 19 Er = 1 return = 576
🐡 🦚 🦤 🐌 🦦
Constraints
:OMore Amazon problems
- Count Promotional PeriodsOA · Seen Jun 2026
- Find Maximum Total Amount (SDE I, Fungible :)Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Find Minimum CostOA · Seen Jun 2026
- Get Smallest Base SegmentOA · Seen Jun 2026
- Select Least Resource TasksOA · Seen Jun 2026
- Product Category Group SizesPHONE SCREEN · Seen May 2026
- Count Connected ComponentsPHONE SCREEN · Seen May 2026
public int minimumEnergyCost(int[] weights, int X, int Y, int El, int Er) {
// write your code here
}
weights[42, 3, 99]
X4
Y4
El19
Er1
expected576
sign in to submit