Tap here to switch tabs
Problem
Submissions

Problem: Eat Pizzas!

Try to solve the Eat Pizzas! problem.

Statement

You are given an integer array pizzas of length n, where pizzas[i] represents the weight of the pizza at index i.

Every day, you choose exactly 44 pizzas to eat until all pizzas are consumed, taking a total of n/4n / 4 days.

The weight gained each day is determined as follows:

  • On odd days (day 11, day 33, day 55, and so on), you gain weight equal to the maximum weight among the 44 selected pizzas.

  • On even days (day 22, day 44, day 66, and so on), you gain weight equal to the second largest weight among the 44 selected pizzas.

Return the maximum total weight you can gain after eating all pizzas.

Constraints:

  • 4≤n==4 \leq n == pizzas.length ≤2imes105\leq 2 imes 10^5

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

  • n is a multiple of 44

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Eat Pizzas!

Try to solve the Eat Pizzas! problem.

Statement

You are given an integer array pizzas of length n, where pizzas[i] represents the weight of the pizza at index i.

Every day, you choose exactly 44 pizzas to eat until all pizzas are consumed, taking a total of n/4n / 4 days.

The weight gained each day is determined as follows:

  • On odd days (day 11, day 33, day 55, and so on), you gain weight equal to the maximum weight among the 44 selected pizzas.

  • On even days (day 22, day 44, day 66, and so on), you gain weight equal to the second largest weight among the 44 selected pizzas.

Return the maximum total weight you can gain after eating all pizzas.

Constraints:

  • 4≤n==4 \leq n == pizzas.length ≤2imes105\leq 2 imes 10^5

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

  • n is a multiple of 44