modified cumulative algorithm