Why? csum[i]=csum[i-1]+p[i];

why should we add csum[i-1] i understood p[i] should be added but why csum[i-1]