Some DP (dynamic programming) problems have cost functions with absolute values: . The naive solution checks every possible value.
With large ranges, this takes too long. I'll show you how to represent these functions by their slope changes. You'll use priority queues to track breakpoints where slopes shift, avoiding computation of all values. By the end, you'll solve problems with ranges up to in time instead of timing out.