A festival ground is divided into n zones numbered 1..n, all starting empty. m bookings arrive; booking j is described by l r p, meaning p attendees are assigned to every zone from l to r inclusive (1-indexed). After all bookings are applied, report the maximum occupancy of any single zone.
Line 1: two integers n and m.
Next m lines: three integers l, r, p.
A single integer: the largest occupancy across all zones after every booking is applied.
Example 1
Input
5 3 1 3 2 2 5 3 4 4 1
Expected
5
Explanation
After the three bookings the zones hold 2, 5, 5, 4, 3. The busiest zone holds 5.
Example 2
Input
4 2 1 4 5 2 3 5
Expected
10
Explanation
Zones become 5, 10, 10, 5. The peak occupancy is 10.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →