A limit theorem for the maximum of cumulative sums