Quantum Algorithms and Lower Bounds for Finite-Sum Optimization