← 返回 amazon 的题目列表Maximum Total Value in a Fixed-Length Window
类型:online_judge
You are given n pairwise non-overlapping closed integer intervals. Each interval is represented as [l, r, value].
Every integer position p with l <= p <= r contains one bag with value value.
Positions not covered by any interval have value 0.
Choose a contiguous integer interval of exactly length k, namely [x, x + k - 1].
Return the maximum total value of all bags contained in such a window.
Input Format
n k
l1 r1 value1
l2 r2 value2
...
ln rn valuen
Output Format
Print one integer: the maximum total value obtainable from a contiguous window of exactly length k.
Constraints
1 <= n <= 2 * 10^5
1 <= k <= 10^9
1 <= l_i <= r_i <= 10^9
0 <= value_i <= 10^9
Intervals are pairwise non-overlapping, but may be given in arbitrary order.
Example
Input:
3 4
1 3 2
5 6 4
8 10 1
Output:
10
Explanation: choose [3, 6], whose total is 2 + 0 + 4 + 4 = 10.
Example
Input
3 4
1 3 2
5 6 4
8 10 1
Output
10