D Wand ring Atcoder Contest

Can some please help in understanding the solution for the problem D-Wand ring ???

This is solution but i cant able to understand the solution. pls help


using namespace std;
typedef long long ll;
const int mod=998244353;
ll a[200005],ans=0,mxs=0,now=0;
int n;
int main(){
for(int i=1;i<=n;i++){
return 0;

Since you are required to find the max of coordinates obtained at each step, for each index i, we are obtaining the cumulative sum and also keeping track of the max positive value we get so far-
mxs=max(mxs, a[i]) This does the following.

At last the answer would be, maximum of current position+ the max positive coordinate you reached.

i think that now is mantained wrongily.
for eg
input 2 -1 -2
now when its coming at -2, that total corrct travrsal was 3 before. so 3+maxi(cumalitive sum till now=2) so 3+2=5
but accoring to program, i think now is a[0]+a[1]=1 but 1+2=3 is wrogn for coming at psoition 3