#3457

Eat Pizzas!

expert · 1100 · lc medium +32 · 33.1% accepted · 107 likes · top 11%

Description

An array pizzas gives the weight of each pizza. Each day you consume exactly 4 pizzas. Due to metabolism, eating four pizzas of weights W <= X <= Y <= Z only contributes one pizza\'s weight:

- On odd days (1-indexed), you gain weight Z.

- On even days, you gain weight Y.

Choose how to group all pizzas into daily sets to maximize total weight gained. Each pizza is eaten exactly once, and n is guaranteed to be a multiple of 4.

Code

1
2
3