WA in #LIFTME

Why is my solution giving WA. Can anybody help?

my solution:-

#include<iostream>
#include<bits/stdc++.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include <numeric> 
#define wl int t;cin>>t;while(t--)
#define ll long long
#define ul unsigned long
#define fast  std::ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std; 
long int m= 100001;

inline long fs(long a,long b,long l)
{
	return((abs(a-l)+abs(b-a)));
}

int main()
{
	fast
	wl
	{
	  long n,q;
	  cin>>n>>q;
	   long e=0;	
	   int fl=0;
	  	for(int i=1;i<=q;i++)
	  	{
	  		long f,d;
	  		cin>>f>>d;
	  		
	  		fl=(fl+fs(f, d, e)%m);
	  		e=d;
		  }
		  cout<<fl<<endl;
	}
	return 0;
}

the logic of your code is completely correct, but you have defined m = 100001 and printing the ans mod m but the ans can be large upto 10^9

2 Likes

But one of the constraint was the sum of all the queries Q must not exceed 10^5.
So accordingly I’ve done…if that is wrong then what else will replace it?

the sum Q over all test cases does not exceed 10^5 means T*Q will never exceed 10^5 and is not related with the answer.

1 Like

Well thank u so much @coder_yash_23 :innocent: :innocent: