Joint Subcarrier and Power Allocation in NOMA: Optimal and Approximate Algorithms