Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 319C Kalila and Dimna - Why It Works

The conditions

Slopes bib_i are strictly decreasing. When we add lines in order i=1,2,i = 1, 2, \ldots, each new line has a smaller slope than all previous. Lines are added to the deque in decreasing slope order. For queries: we need aja_j values. The problem states a1<a2<<ana_1 < a_2 < \ldots < a_n (increasing).

So queries are sorted too. Both conditions met: sorted slopes (decreasing) and sorted queries (increasing). The simple O(n)O(n) deque CHT applies directly.