Algorithms and matching lower bounds for approximately-convex optimization