Tap here to switch tabs
Problem
Submissions

Problem: Delivering Boxes from Storage to Ports

med
30 min
Try to solve the Delivering Boxes from Storage to Ports problem.

Statement

You are given an array boxes, where boxes[i] = [ports_i, weights_i] denotes that the iextthi^{ ext{th}} box needs to be delivered to the port ports_i and has a weight of weights_i. You are also given integers portsCount, maxBoxes, and maxWeight.

There is a ship located at a storage facility that can deliver the boxes. The ship operates under the following conditions:

  • The boxes must be delivered in the exact order they are listed in boxes.

  • In a single journey, the ship can load at most maxBoxes boxes.

  • In a single journey, the total weight of the loaded boxes cannot exceed maxWeight.

  • The ship begins each journey at the storage facility, delivers the current batch of boxes to their respective ports in order, and then returns to the storage facility.

  • Traveling from the storage facility to a port, traveling from one port to another distinct port, or traveling from a port back to the storage facility each counts as 11 trip. Staying at the same port to deliver consecutive boxes destined for that port does not add extra trips.

Return the minimum total number of trips required to deliver all the boxes and return the ship to the storage facility.

Constraints:

  • 1≤1 \leq boxes.length ≤105\leq 10^5

  • 1≤1 \leq portsCount, maxBoxes, maxWeight ≤105\leq 10^5

  • 1≤1 \leq ports_i ≤\leq portsCount

  • 1≤1 \leq weights_i ≤\leq maxWeight

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Delivering Boxes from Storage to Ports

med
30 min
Try to solve the Delivering Boxes from Storage to Ports problem.

Statement

You are given an array boxes, where boxes[i] = [ports_i, weights_i] denotes that the iextthi^{ ext{th}} box needs to be delivered to the port ports_i and has a weight of weights_i. You are also given integers portsCount, maxBoxes, and maxWeight.

There is a ship located at a storage facility that can deliver the boxes. The ship operates under the following conditions:

  • The boxes must be delivered in the exact order they are listed in boxes.

  • In a single journey, the ship can load at most maxBoxes boxes.

  • In a single journey, the total weight of the loaded boxes cannot exceed maxWeight.

  • The ship begins each journey at the storage facility, delivers the current batch of boxes to their respective ports in order, and then returns to the storage facility.

  • Traveling from the storage facility to a port, traveling from one port to another distinct port, or traveling from a port back to the storage facility each counts as 11 trip. Staying at the same port to deliver consecutive boxes destined for that port does not add extra trips.

Return the minimum total number of trips required to deliver all the boxes and return the ship to the storage facility.

Constraints:

  • 1≤1 \leq boxes.length ≤105\leq 10^5

  • 1≤1 \leq portsCount, maxBoxes, maxWeight ≤105\leq 10^5

  • 1≤1 \leq ports_i ≤\leq portsCount

  • 1≤1 \leq weights_i ≤\leq maxWeight