A load balancer applies m reservation requests to n servers, indexed 1..n. Each request l r w adds w units of load (which may be negative) to every server in the inclusive range [l, r]. After applying all m requests, determine the index (1-based) of the server with the MAXIMUM total load. If multiple servers tie for the maximum, print the smallest such index.
Line 1: two integers n m.
Next m lines: three integers l r w each.
A single integer: the 1-based index of the server with the maximum total load (smallest index on ties).
Example 1
Input
5 3 1 3 5 2 5 -2 4 4 10
Expected
4
Explanation
Loads evolve [5,5,5,0,0] then [5,3,3,-2,-2] then [5,3,3,8,-2]; the maximum is 8 at server 4.
Example 2
Input
3 0
Expected
1
Explanation
No requests are applied, so every server has load 0; the smallest tied index is 1.
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 →