tubeshowcase●1,670,413 videos♡ My collection 0
← Learn to Code

Learn to Code10:51

Competitive Programming Tutorial #42 | Convex hull trick: turn the DP into lines

SyntaxPilot ↗

From the creator

Competitive Programming Tutorial: Episode 42 of SyntaxPilot's free Competitive Programming full course, with real-life examples for every concept. Convex hull trick: turn the DP into lines. In this video you'll learn: • Original Problem S (Auto Hops): greedy switching fails • Why the O(n²) DP gets TLE at n = 10^6 • The key observation: every earlier state is a line • The lower envelope, with a phone-plan example • Monotone CHT: push at the back, query from the front • The bad() test with cross-multiplication and __int128 • A stress test against the O(n²) DP • Real bug: intersections with integer division (SIGFPE, wrong answer) Every concept starts with a real-life example, then an animation and notes, then live code in the SyntaxPilot online compiler. Practice free in the SyntaxPilot compiler (nothing to install): https://syntaxpilot-learning-2026.web.app/ Detailed notes for this episode (code, outputs, practice): https://syntaxpilot-learning-2026.web.app/notes/cp/cp_ep42/ Chapters 00:00 Welcome 00:23 Today's agenda 00:42 Auto hops on a highway 01:46 Greedy switching: WA 02:13 The O(n²) DP: TLE 02:47 Every state is a line 03:32 Phone plans: lowest line 04:29 The monotone hull 06:22 Accepted + stress test 07:25 The division bug 08:15 Complexity vs the constraints 08:41 Common mistakes 09:03 What you invented 09:26 Quick quiz 09:52 Recap and homework 10:29 Next episode Next episode: DP optimisation 3: divide and conquer DP Post your homework and quiz answer in the comment

Published 2026-11-19 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code