Cost-Optimal Grouped-Query Attention for Long-Context LLMs