Intervals

You are given n closed, integer intervals [ai, bi] and n integers c1, . . . , cn. Write a program that: • reads the number of intervals, their endpoints and integers c1, . . . , cn from the standard input, • computes the minimal size of a set Z of integers which has at least ci common elements with interval [ai,bi], for each i = 1,2,...,n, • writes the answer to the standard output. Input The first line of the input cointains an integer indicating the number of datasets. It’s followed by a blank line. The first line of each dataset contains an integer n (1 ≤ n ≤ 50000) — the number of intervals. The following n lines describe the intervals. The line i + 1 of the input contains three integers ai, bi, ci separatedbysinglespacesandsuchthat0≤ai ≤bi ≤50000and1≤ci ≤bi−ai+1. There is a blank line between datasets. Output The output for each dataset contains exactly one integer equal to the minimal size of a set Z sharing at least ci elements with interval [ai, bi], for each i = 1, 2, . . . , n. Print a blank line between datasets. Sample Input 1 5 373 8 10 3 681 131 10 11 1 Sample Output 6