fork download
  1. #include<iostream>
  2. #include"math.h"
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. float k=0;
  8. long long a=0, b=0, ans=0;
  9. int t=0;
  10. cin >> t;
  11. while(t--)
  12. {
  13. long long t1=0, t2=0;
  14.  
  15. cin >> k >> t1 >> t2; // Taking input in temprory variables.
  16. float temp = k/2; //To know weather its even or odd.
  17.  
  18. a = max(t1, t2);//a will store max one
  19. b = min(t1, t2);//b will store min one
  20.  
  21. //if (a-b > k/2)
  22. if(a-b > temp)
  23. {
  24. ans = (k-a)+b-1;
  25. }
  26.  
  27. //if (a-b < k/2)
  28. else if(a-b < temp)
  29. {
  30. ans = (a-b)-1;
  31. }
  32.  
  33. //otherwise a:b is forming a diameter
  34. else
  35. {
  36. ans = 0;
  37. }
  38.  
  39. cout << ans << endl;
  40. }
  41. }
Success #stdin #stdout 0s 15240KB
stdin
4
3 3 1
6 1 3
6 1 4
10 1 5
stdout
0
1
0
3