Weekly Contest 195 Q4 pseudo code

We want to find the biggest previously yi - xi for each point_j = (xj, yj).

	maxHeap = new MaxHeap  // max heap evaluates the point by the point's y - x
	res = -infinity
	for point in points:
		while (maxHeap is not empty) && (point.x - maxHeap.top.x > k)  // maxHeap.top.x is the heap top point's x value.
			maxHeap.pop()
		if (maxHeap is not empty):
			res = max {res, maxHeap.top.value + point.y + point.x}
		maxHeap.push(point)
	return res
Comments (0)