I need to know what’s wrong in here…
while(t–){
cin>>n>>q; ll a[2*q],ans=0; Fi(2*q){ cin>>a[i]; } ans=a[0]; for(ll i=1;i<2*q;i++){ ans += abs(a[i-1]-a[i]); } cout<<ans; }
Full Solution : Go Here
your logic is perfect the only thing you forgot was cout<<ans<<"\n"; or cout<<ans<<endl;
damn…*facepalm thnx
Why am i also getting wrong answer? https://www.codechef.com/viewsolution/32068993
@kavinsingh What you did was right, but you forgot to reset the g variable after each iteration. Also g must be equal to the absolute value of the difference. Here take a look. I corrected your code. Corrected code
@prog_am_er thanks bro ,really appreciate your help.