Customer satisfaction

3.5

32 votes
Binary Search, Algorithms
Problem

Alice is the biggest seller in the town who sells notebooks. She has N customers to satisfy. Each customer has three parameters Li, Ri, and Zi denoting the arrival time, departure time, and quantity of notebooks required.

Each customer has to be supplied a total of Zi notebooks between Li and Ri inclusive. What is the minimum rate of W notebooks per unit time by which if Alice produces so that it satisfies the demand of each customer?

Note that Alice does not need to supply Zi to customer i for per unit time but the total of Zi between Li and Ri and distribution does not need to be uniform.

Input format

  • The first line contains T denoting the number of test cases.
  • The first line of each test case contains an integer N.
  • Next N lines of each test case contains three space-seperated integers Li, Ri, and Zi as described in the problem statement,

Output format

For each test case, print a single line containing the minimum rate of production W.

Constraints

1T1000

1N200000

1L[i],R[i],Z[i]200000i[1,N]

L[i]R[i]i[1,N]

Ti=1N200000

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

For W=2,

for t=2 we alice will produce 4 notebooks so he will satisfy 1st and 2nd customer leading now he has 0 notebooks and t=3 he will have 2 notebooks which he has produced during t=2 and t=3 and satisfy customer 3.

For W=1 he will be unable to satisfy all three.

Editor Image

?