BudgetMem: Learning Selective Memory Policies for Cost-Efficient Long-Context Processing in Language Models