Subarray max sum (cumulative sum) doubt

I didn’t get why have we written
cin >> a[0];
cumsum[0] = a[0];
outside the loop .We could have done it within the loop also.
And I also didn’t get the meaning of
cumsum[i] = cumsum[i-1] + a[i];
Basically I want to know what does it do.

Hello @anusha_garg
cin >> a[0];
this should be cin>>a[i];
cumsum[0] = a[0];
and this we are doing to assign the 0th position in cumsum array at till this point i.e till 0 .
cumsum[i] = cumsum[i-1] + a[i];
from here we are calculating the further cumulative sum .
as you can see here we are doing cumsum[i-1] thats why we have already stored for cumsum[0] because when at index 1 cumsum[1-1] will give from cumsum[0].
and this whole process is to calculate the cummulative sum till any point.
like:
suppose the array is:
1 2 3 then cumsum[0]=a[0]=1
and according to the loop
cumsum[1]=cumsum[1-1]+a[1]=>1+2=3;
cumsum[2]=cumsum[2-1]+a[2]=>3+3=6;
in this way it will be done: