Peak Load Dispatch Plan
Context
A warehouse schedules shipments in a fixed dispatch order. Each shipment has a load rating, which may be positive, zero, or negative after adjustments. A valid dispatch plan selects shipments in order, with ratings strictly rising up to one peak and then strictly falling. Find the greatest possible total rating.
Problem
Given an integer array of shipment load ratings, choose a subsequence whose values strictly increase up to a peak and then strictly decrease after that peak. The increasing or decreasing side may be empty, so a single shipment and a monotonic subsequence are valid. Selected items must keep their original order, and skipped items are allowed. Return the largest possible sum of the selected ratings. Repeated values cannot be used for a strict increase or decrease.
Examples
loads = [2, 5, 9, 7, 3]26loads = [1, 3, 5, 7]16loads = [-6, -2, -4, -8]-2Constraints
1 <= len(loads) <= 100-10000 <= loads[i] <= 10000 for every i- Types:
loadsis int[]; result is int
Function signature
def maximum_peak_dispatch_sum(loads: list[int]) -> int
loadslist[int]- Shipment load ratings in their fixed dispatch order.
- returns int
- The greatest sum among all valid strictly increasing-then-decreasing subsequences.
Adapted from MBPP problem task_245 (CC BY 4.0). Rewritten, extended and verified by Iksha.
Notes
- A peak may be the first or last selected shipment.
- The input is not required to be sorted, distinct, or positive.