make code that does this algorithm in c++:
	\begin{algorithm}
The following algorithm correctly solves the problem:
\\ \\
\textbf{Step 1: Read Input:}
Read integers \( n \) and \( m \), the binary string \( b\_str \) of length \( n \), and the array \( c_0 \) containing \( n \) double values.
\\ \\
\textbf{Step 2: Initialize \( D_0 \) and \( C_0 \):}
Set \( D_0 \gets 0.0 \) (cumulative difference based on categories) and \( C_0 \gets 0.0 \) (total initial sum). \\
For each index \( i = 1 \) to \( n \):
\begin{itemize}
    \item If \( b\_str[i] = \text{'1'} \), then \( D_0 \gets D_0 + c_0[i] \).
    \item Otherwise, \( D_0 \gets D_0 - c_0[i] \).
    \item Update \( C_0 \gets C_0 + c_0[i] \).
\end{itemize} 
\\ \\
\textbf{Step 3: Initialize Summations and Current Sum:}
Set \( \text{sum\_A} \gets 0.0 \) (accumulator for category '1'), \( \text{sum\_B} \gets 0.0 \) (accumulator for category '0'), and \( C \gets C_0 \) (current total sum).
\\ \\
\textbf{Step 4: Perform \( m \) Iterations:}
For each iteration \( t = 0 \) to \( m-1 \):
\begin{itemize}
    \item Update \( \text{sum\_A} \gets \text{sum\_A} + \ln\left(1 + \frac{1}{C}\right) \).
    \item Update \( \text{sum\_B} \gets \text{sum\_B} + \ln\left(1 - \frac{1}{C}\right) \).
    \item Update \( C \gets C + \frac{D_0 + t}{C} \) (adjust the current sum based on cumulative difference and iteration).
\end{itemize}
\\ \\
\textbf{Step 5: Compute Multiplicative Factors:} 
Calculate \( \text{factor\_A} \gets e^{\text{sum\_A}} \) (scaling factor for category '1') and \( \text{factor\_B} \gets e^{\text{sum\_B}} \) (scaling factor for category '0').
\\ \\
\textbf{Step 6: Compute Expected Values} \\
For each index \( i = 1 \) to \( n \):
\begin{itemize}
    \item If \( b\_str[i] = \text{'1'} \), then \( \mathbb{E}[c_i(m)] \gets c_0[i] \times \text{factor\_A} \).
    \item Otherwise, \( \mathbb{E}[c_i(m)] \gets c_0[i] \times \text{factor\_B} \).
\end{itemize}
\\ \\
\textbf{Step 7: Output Expected Values:} 
Output \( \mathbb{E}[c_i(m)] \) for all \( i = 1 \) to \( n \) with fixed decimal precision.
\end{algorithm}
		\begin{center}
			\noindent\rule{6in}{1.5pt}
		\end{center}
		
		\textbf{Proof of Correctness}
\begin{lemma}
\label{lem:initial_sums}
After initialization, the variables satisfy:
\[
C_0 = \sum_{i=1}^{n} c_0[i] \quad \text{and} \quad D_0 = \sum_{i=1}^{n} c_0[i] \cdot (2b_i - 1)
\]
where \( b_i = 1 \) if \( b\_str[i] = \text{'1'} \) and \( b_i = 0 \) otherwise.
\end{lemma}

\begin{proof}
By the initialization loop:
\[
C_0 = \sum_{i=1}^{n} c_0[i]
\]
and
\[
D_0 = \sum_{i=1}^{n} \begin{cases}
c_0[i], & \text{if } b\_str[i] = \text{'1'} \\
- c_0[i], & \text{if } b\_str[i] = \text{'0'}
\end{cases}
= \sum_{i=1}^{n} c_0[i] \cdot (2b_i - 1)
\]
\end{proof}

\begin{lemma}
\label{lem:sum_factors}
After \( m \) iterations, the accumulators satisfy:
\[
\text{sum\_A} = \sum_{t=0}^{m-1} \ln\left(1 + \frac{1}{C_t}\right) \quad \text{and} \quad \text{sum\_B} = \sum_{t=0}^{m-1} \ln\left(1 - \frac{1}{C_t}\right)
\]
where \( C_{t+1} = C_t + \frac{D_0 + t}{C_t} \).
\end{lemma}

\begin{proof}
The algorithm iteratively updates \( \text{sum\_A} \) and \( \text{sum\_B} \) by adding \( \ln\left(1 + \frac{1}{C}\right) \) and \( \ln\left(1 - \frac{1}{C}\right) \) respectively in each iteration \( t \). The current sum \( C \) is updated as:
\[
C_{t+1} = C_t + \frac{D_0 + t}{C_t}
\]
Thus, after \( m \) iterations:
\[
\text{sum\_A} = \sum_{t=0}^{m-1} \ln\left(1 + \frac{1}{C_t}\right)
\]
\[
\text{sum\_B} = \sum_{t=0}^{m-1} \ln\left(1 - \frac{1}{C_t}\right)
\]
\end{proof}

\begin{lemma}
\label{lem:factor_exponents}
The multiplicative factors satisfy:
\[
\text{factor\_A} = \prod_{t=0}^{m-1} \left(1 + \frac{1}{C_t}\right) \quad \text{and} \quad \text{factor\_B} = \prod_{t=0}^{m-1} \left(1 - \frac{1}{C_t}\right)
\]
\end{lemma}
\begin{proof}
By definition:
\[
\text{sum\_A} = \sum_{t=0}^{m-1} \ln\left(1 + \frac{1}{C_t}\right) \implies \text{factor\_A} = e^{\text{sum\_A}} = \prod_{t=0}^{m-1} \left(1 + \frac{1}{C_t}\right)
\]
Similarly:
\[
\text{sum\_B} = \sum_{t=0}^{m-1} \ln\left(1 - \frac{1}{C_t}\right) \implies \text{factor\_B} = e^{\text{sum\_B}} = \prod_{t=0}^{m-1} \left(1 - \frac{1}{C_t}\right)
\]
\end{proof}

\begin{theorem}
\label{thm:correctness}
After executing the algorithm, for each \( i \in \{1, 2, \dots, n\} \):
\[
\mathbb{E}[c_i(m)] = c_0[i] \cdot \begin{cases}
\text{factor\_A}, & \text{if } b_i = 1 \\
\text{factor\_B}, & \text{if } b_i = 0
\end{cases}
\]
\end{theorem}

\begin{proof} From Lemma \ref{lem:initial_sums}, we have:
\[
C_0 = \sum_{i=1}^{n} c_0[i], \quad D_0 = \sum_{i=1}^{n} c_0[i] \cdot (2b_i - 1)
\]
At each operation \( t \), the algorithm updates:
\[
\text{sum\_A} \leftarrow \text{sum\_A} + \ln\left(1 + \frac{1}{C_t}\right)
\]
\[
\text{sum\_B} \leftarrow \text{sum\_B} + \ln\left(1 - \frac{1}{C_t}\right)
\]
\[
C_{t+1} = C_t + \frac{D_0 + t}{C_t}
\]
By Lemma \ref{lem:sum_factors}, after \( m \) operations:
\[
\text{sum\_A} = \sum_{t=0}^{m-1} \ln\left(1 + \frac{1}{C_t}\right), \quad \text{sum\_B} = \sum_{t=0}^{m-1} \ln\left(1 - \frac{1}{C_t}\right)
\]
And by Lemma \ref{lem:factor_exponents}:
\[
\text{factor\_A} = \prod_{t=0}^{m-1} \left(1 + \frac{1}{C_t}\right), \quad \text{factor\_B} = \prod_{t=0}^{m-1} \left(1 - \frac{1}{C_t}\right)
\]For each element \( i \):
\[
\mathbb{E}[c_i(m)] = c_0[i] \cdot \begin{cases}
\prod_{t=0}^{m-1} \left(1 + \frac{1}{C_t}\right), & \text{if } b_i = 1 \\
\prod_{t=0}^{m-1} \left(1 - \frac{1}{C_t}\right), & \text{if } b_i = 0
\end{cases}
= c_0[i] \cdot \begin{cases}
\text{factor\_A}, & \text{if } b_i = 1 \\
\text{factor\_B}, & \text{if } b_i = 0
\end{cases}
\]
\end{proof}
        
		\begin{center}
			\noindent\rule{6in}{1.5pt}
		\end{center}
		
		\begin{claim}
			The following algorithm has a time complexity of \( \boxed{O(n + m)} \).
		\end{claim}
		\begin{proof}
			The algorithm operates through three primary phases, each contributing to its overall time complexity. Initially, it computes the sum \( S = \sum_{i=1}^{n} c_i \) by iterating through the \( n \) elements of the vector \( \mathbf{c} \), which requires \( O(n) \) time. Following this, the algorithm calculates the expected changes \( \Delta c_i = \frac{c_i}{S} \times (2b_i - 1) \) for each index \( i \) by processing each of the \( n \) elements once, also taking \( O(n) \) time. In the third phase, the algorithm determines the expected values \( \mathbb{E}[c_i(m)] = c_i + m \times \Delta c_i \) for each of the \( n \) elements, which again necessitates \( O(n) \) time. Additionally, the final step involves outputting the \( n \) expected values, requiring another \( O(n) \) time. 
            \newline\newline
            Summing the time complexities of all these phases initially suggests a total of \( O(n) \). However, considering that the algorithm must also handle \( m \) operations independently, which introduces an additional \( O(m) \) component, the overall time complexity is therefore \( O(n + m) \). This linear relationship ensures that the algorithm scales efficiently with both the number of elements \( n \) and the number of operations \( m \), maintaining optimal performance even as these parameters grow large.
		\end{proof}