Dynamic Programming21 sections · 916 units
Open in Course

Common Mistakes

What to avoid

1.1. Sign errors: If you want minimum and slopes are increasing, you need the upper envelope, not lower. Double-check your setup.

2.2. Wrong domination check: The intersection formula can have division issues. Use cross-multiplication to avoid floating point.

3.3. Forgetting the extra term: Remember to add back si2s_i^2 or whatever you factored out.

4.4. Overflow: mxm \cdot x can overflow 64-bit integers. Use 128-bit or __int128 if needed.

5.5. Off-by-one: Process lines before querying. Don't query with a line you haven't added yet.