fork(1) 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. cout << "k = " << k << endl;
  19.  
  20. a = max(t1, t2);//a will store max one
  21. b = min(t1, t2);//b will store min one
  22.  
  23. //if (a-b > k/2)
  24. if(a-b > temp)
  25. {
  26. ans = k-(a-b-1);
  27. }
  28.  
  29. //if (a-b < k/2)
  30. else if(a-b < temp)
  31. {
  32. ans = (a-b)-1;
  33. }
  34.  
  35. //otherwise a:b is forming a diameter
  36. else
  37. {
  38. ans = 0;
  39. }
  40.  
  41. cout << ans << endl;
  42. }
  43. }
Success #stdin #stdout 0s 15240KB
stdin
4
1000001 1 2
5 1 3
6 1 4
10 1 5
stdout
k = 1e+06
0
k = 5
1
k = 6
0
k = 10
3