Farmer John's $N$ cows ($1 \le N \le 10{,}000$) are numbered $1$ through $N$. Milking cow $i$ takes $T(i)$ units of time. Because of the layout of the barn, some cows must be milked before others: if cow $A$ must be milked before cow $B$, then John must completely finish milking $A$ before he can start milking $B$.
To finish as quickly as possible, John has hired enough farmhands to milk any number of cows at the same time. Even so, the ordering constraints limit how fast the whole process can go. Compute the minimum total time needed to milk all of the cows.
In the first example there are $3$ cows, and milking each of them takes $10$, $5$, and $6$ units of time respectively. Cow $3$ must be completely milked before cow $2$ can start.
Cows $1$ and $3$ can be milked at the same time from the beginning. Once cow $3$ is finished, cow $2$ can start. All cows finish being milked after $11$ units of time.