function solve(points, k)
preprocess points (sort, remove dominated)
binary search on lambda
for each lambda, compute dp with CHT
count photos used
adjust search range
return optimal cost - k * lambda
function dpWithCHT(lambda)
hull := empty convex hull structure
for i from 1 to n
dp[i] := query hull at position x[i] + lambda
add line for point i to hull
return (dp[n], count)
The CHT handles the quadratic cost function. Combined with Aliens Trick. Time: , Space: .
Time complexity: .
Space complexity: .