AmazonOA #111
Cinema Shows
Estimated HardJudge-ready
Topics (AI-labelled)Scheduling DPBinary Search
Choose some screenings, where a screening ends at start+duration. Two screenings do not conflict only if one ends strictly before the other starts; equal endpoints are not allowed. Find the maximum total audience. The source's second example confirms the strict inequality.
Input
The first line contains n (1..100000), followed by three lines start, duration and volume; the first two are in 1..10⁹, and volume is in 1..1000.
Output
Output a single integer answer.
Example 1
Input:
5
10 5 15 18 30
20 12 20 35 35
50 51 20 25 10
Output:
76
Example 2
Input:
3
1 2 4
2 2 1
1 2 3
Output:
4
Example 3
Input:
2
1 3
2 1
5 7
Output:
7
Example notes
Example 1: choose the two screenings starting at 5 and 18, 51+25=76. Example 2: the screening starting at 2 ends at 4, so it cannot be followed by the screening starting at 4; choose the ones starting at 1 and 4, for a total of 4. Example 3: the first screening ends exactly when the second starts, so only the screening with audience 7 can be chosen.
Editorial
Loading solution…