# Prove: $\sum_{n=1}^\infty a_n$ converges iff $\sum_{n=1}^\infty \int_0^{a_n}g(t) \, dt$ converges

Let $$\left \{ a_n \right \}$$ be a positive sequence that converges to zero. And let $$g$$ be an integrable function, continuous at zero such that $$g(0)\ne0$$.

Prove: $$\sum_{n=1}^{\infty}a_n$$ converges iff $$\sum_{n=1}^\infty\int_0^{a_n}g(t)\,dt$$ converges.

My attempt: I try to use the integral test but I don't know how to continue from there and moreover how to use that $$g(0)\ne0$$ and $$g$$ is continuous at zero. Any hints would be appreciated.

Assume $\sum a_n$ converges. Then, using the continuity of $g$ at 0 and the fact that $a_n \to 0$, we have that for $n \in \mathbb{N}$ sufficiently large, $$(g(0) - 1)a_n \leq \int_0^{a_n} g (t) dt \leq (g(0) + 1)a_n.$$
Since both sides of the inequality converge when you sum over $n$, we get the convergence of the series with integrals.
Now the opposite, assume $\sum \int_0^{a_n} g (t) dt$ converges , and without loss of generality assume $g(0) > 0$. Then, from the continuity of $g$ at 0, and the fact that $a_n \to 0$, we have $\int_0^{a_n} g(t) dt \geq ( g(0) - \epsilon ) a_n$ for $n$ large enough, where $\epsilon >0$ is fixed so that $( g(0) - \epsilon ) >0$. Now the series with integrals, which converges, dominates the series with $a_n$, hence the convergence of $\sum a_n$.