Skip to content

Commit 995a6b4

Browse files
authored
Update Lagrange.mdx
1 parent 7aede41 commit 995a6b4

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

content/6_Advanced/Lagrange.mdx

+11-1
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,20 @@ This idea almost works but there are still some very important caveats and condi
7474

7575
Let $f(x)$ be the maximal sum if we use at most $x$ subarrays. We want to find $f(K)$.
7676

77-
The first condition is that $f(x)$ **must be concave or convex**. Since $f(x)$ is increasing in this problem, the means that we want $f(c)$ to be concave: $f(x) - f(x - 1) \ge f(x + 1) - f(x)$. Intuitively speaking, this means that the more subarrays we add, the less we increase our answer by.
77+
The first condition is that $f(x)$ **must be concave or convex**. Since $f(x)$ is increasing in this problem, the means that we need $f(x)$ to be concave: $f(x) - f(x - 1) \ge f(x + 1) - f(x)$. In other words, this means that the more subarrays we add, the less we increase our answer by. We can intuitively see that this is true.
7878

7979
<Spoiler title="Proof that our function is concave">
8080

81+
We construct a flow graph with source $S$, sink $T$, and $N+1$ additional vertices numbered $1$ to $N+1$. We will have the following edges.
82+
83+
- A directed edge from $S$ to $i$ ($1 \le i \le N+1$) with weight $0$ and capacity $1$.
84+
85+
- A directed edge from $i$ ($1 \le i \le N+1$) to $T$ with weight $0$ and capacity $1$.
86+
87+
- A bidirectional edge from $i$ ($1 \le i \le N$) to $i+1$ with weight $A[i]$ and capacity $1$.
88+
89+
$f(x)$ will be the maximum cost $x$-flow through the graph. We can repeatidly find the maximum cost augmenting path $x$ times to get our answer. Because the maximum cost as a function of flow is concave, $f(x)$ will be concave. You can read more about simulating cost flows [here](https://codeforces.com/blog/entry/118391).
90+
8191
</Spoiler>
8292

8393
Consider the following graphs of $f(x)$ and $f(x)-\lambda x$. In this example, we have $\lambda=5$.

0 commit comments

Comments
 (0)