WA in LIFTME

why is the code giving WA

https://www.codechef.com/viewsolution/32042765

sum has to be long .Same case happened with me for 1 hour.

defined as long long int already above

a[0] not used.

For the first query, you are incrementing your sum by b[z] if z is zero. You are just adding the destination floor.
If the query is 3 1, it should count 4 floors, your code will count only 1.

i did
int curr=0;
int r[][]=new int [q][n]
for(int i=0;i<q;i++){
sum=Math.abs(r[i][0]-curr)+Math.abs(r[i][1]-r[i][0]);
curr=r[i][1];
}

okh I understand thanks

btw it should count 5

oh yeah sorry my bad. It’ll be 5.