SnowflakeOA #11
Maximum Order Volume (Weighted Interval Scheduling)
Estimated HardJudge-ready
Topics (AI-labelled)Scheduling DPBinary Search
A supermarket receives n calls in one day. Each call has a start time start, a duration duration, and an order volume volume. Choose non-conflicting calls to maximize the total order volume. Following the source's implementations in three languages, call intervals are half-open [start, start+duration): when one call ends exactly when the next one starts, both calls can be taken back to back.
Original constraints: 1≤n≤100000, 1≤start[i], duration[i], volume[i]≤10^9.
Input
The first line contains n; the next three lines contain the n values of start, duration, and volume, respectively.
Output
Output the maximum total order volume that can be obtained.
Example 1
Input:
5
10 5 15 18 30
30 12 20 35 35
50 51 20 25 10
Output:
76
Example notes
Sort by end time. Let dp[i] be the maximum order volume using the first i calls; when choosing call i, binary search for the number p of calls whose end time is no later than its start time, and the transition is max(dp[i-1], dp[p]+volume[i]).
Editorial
Loading solution…