To avoid hitting the cost cap, combine your enchantments in pairs. Instead of adding books one-by-one to your sword, combine book A with B, and C with D, then combine those two results together. This keeps the total number of operations on the final item much lower.