I am going through machine learning course on coursera. While going through the section on neural networks I came across the cost function for multi - classification problem using neural networks ( ignoring the regularization term ): $$\begin{gather*} J(\Theta) = - \frac{1}{m} \sum_{i=1}^m \sum_{k=1}^K \left[y^{(i)}_k \log ((h_\Theta (x^{(i)}))_k) + (1 - y^{(i)}_k)\log (1 - (h_\Theta(x^{(i)}))_k)\right] \end{gather*}$$
where $m$ is the number of training data points $\{(x_1,y_1),...(x_m,y_m)\}$. Each data point is classified into one of the $K$ categories ie. $1\;\le{\;y_i}\;\le{K}$ ( so $y_k^{(i)}$ means if $\;y_k^{(i)} == k\;$ ). And $h_\Theta$ is the hypothesis function.
My doubt is why does the cost function has a summation over $K$. Why aren't there $K$ separate cost functions ( $ 1 \; \le{k} \le K$ ), and we have different $\Theta$ when we minimize each of the $K$ cost functions separately:
$$\begin{gather*} J(\Theta)_k = - \frac{1}{m} \sum_{i=1}^m \left[y^{(i)}_k \log ((h_\Theta (x^{(i)}))_k) + (1 - y^{(i)}_k)\log (1 - (h_\Theta(x^{(i)}))_k)\right] \end{gather*}$$
In the second approach we are trying one-vs-all classification. How is it different from first approach. First approach is taking sum over all cost functions of second approach. So minimization problem being solved in both cases are different. But I am unable to pin point what the difference between the two approaches is ? Both seem intuitively correct to me. Am I doing some stupid mistake ?