Evaluating the limit of a sum using integration 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?
Related question
 A: Here is a clumsy criterion:

Proposition. Let $(a_n)$ be a sequence of positive numbers and write $s_n = \sum_{i=1}^{n} a_i$ for the partial sums. Then the followings are equivalent:
  
  
*
  
*For any Riemann-integrable $f : [0, 1] \to \mathbb{R}$,
  $$ \lim_{n\to\infty} \sum_{i=1}^{n} f\left(\frac{s_i}{s_n}\right)\frac{a_i}{s_n} = \int_{0}^{1}f(x) \, \mathrm{d}x. $$
  
*$\max\{a_1,\cdots,a_n\}/s_n \to 0$ as $n\to\infty$.

This statement is kind of dumb, since $\max\{a_1,\cdots,a_n\}/s_n$ represents the length of the largest subinterval of the partition in OP's scheme. Then (2) simply requires that the partition becomes finer as $n$ grows.
Proof. Write $\|\Pi\|$ for the mesh-size of the partition $\Pi$. If $f : [0, 1] \to \mathbb{R}$ is Riemann-integrable and $\Pi_n$ is a sequence of partitions of $[0, 1]$ with $\|\Pi_n\|\to 0$, then the associated Riemann sum converges to the integral $\int_{0}^{1} f(x)\,\mathrm{d}x$ as $n\to\infty$.


*

*$(2)\Rightarrow(1)$ : If we choose $\Pi_n = \{s_i/s_n\}_{i=0}^{n}$, then $\|\Pi_n\| = \max\{a_1,\cdots,a_n\}/s_n$, and so, (1) follows.

*$(1)\Rightarrow(2)$ : We prove the contrapositive. Assume that (2) does not hold. Then we can find an interval $[a, b] \subseteq [0, 1]$ with $a < b$ and a subsequence $(n_k)$ such that $[a, b]$ is always contained in one of the subintervals of $\Pi_{n_k}$.
Indeed, negating (2) tells that $\limsup_{n\to\infty} \|\Pi_n\| > 0$, thus by passing to a subsequence, we can assume that $\|\Pi_j\| \geq \epsilon > 0$ holds for all $j$, for some $\epsilon > 0$. Next, for each $j$, pick a subinterval $I_j$ of $\Pi_j$ having length $> \epsilon$. Then we may appeal to the compactness of $[0, 1]$ to extract a further subsequence $\{\Pi_k\}$ for which $\bigcap_k I_k$ is an interval of positive length. (For instance, pick a further subsequence such that the left-endpoints of $I_k$'s converge.)
Once such $[a, b]$ and $\Pi_{n_k}$ are chosen, simply pick $f$ as a Riemann-integrable function which is supported on $(a, b)$ and $\int_{0}^{1} f(x) \, \mathrm{d}x \neq 0$. Then from $\sum_{i=1}^{n_k} f(s_i/s_{n_k}) (a_i/s_{n_k}) = 0$, we know that this Riemann sum does not converge to the integral of $f$.
