Optimal Dynamic Resource Allocation In Activity Networks