One of the first results we learn in definite integral is that if $f(x)$ is Riemann integrable in $(0,1)$ then we have $\lim_{n \to \infty}\dfrac{1}{n}\sum_{i=1}^{n}f\Big(\dfrac{i}{n}\Big) = \int_{0}^{1}f(x)dx$.
I was playing around with this to see if this can be generalized and I found the following. We can rewrite the above result as
$$ \lim_{n \to \infty}\frac{1}{1+1+\ldots\text{$n$-times}}\sum_{i=1}^{n}1\times f\Big(\frac{1+1+\ldots\text{$i$-times}}{1+1+\ldots\text{$n$-times}}\Big) = \int_{0}^{1}f(x)dx. $$
The LHS can be written in the general form given below and we ask ourselves for which sequence $a_i$ does the following hold
$$ \lim_{n \to \infty}\frac{1}{a_1 + a_2 + \ldots + a_n}\sum_{i=1}^{n}a_i f\Big(\frac{a_1 + a_2 + \ldots + a_i}{a_1 + a_2 + \ldots + a_n}\Big) =\int_{0}^{1}f(x)dx. $$
Trivially this holds for $a_i = c$ where $c$ is a non-zero constant and the above result is the case when $c=1$. I also observed that this holds for sequence of natural numbers $a_i = i$ since
$$ \lim_{n \to \infty}\frac{2}{n^2+n}\sum_{i=1}^{n}i f\Big(\frac{i^2+i}{n^2+n}\Big) =\int_{0}^{1}f(x)dx. $$
Experimentally, this also holds for the sequence of prime numbers $a_i = p_n$ and also for the sequence of composite numbers $c_n$.
Question: What are the necessary and sufficient conditions on $a_i$ for the above relation to hold?