fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t;
  6. cin>>t;
  7. while(t--)
  8. {
  9. int str,inte,exp;
  10. cin>>str>>inte>>exp;
  11. if((inte-str)>=exp)
  12. { cout<<0<<endl; continue;}
  13.  
  14. if(str<inte)
  15. {
  16. exp = exp -(inte- str);
  17. str = inte;
  18. }
  19.  
  20. if((exp+inte)<str)
  21. cout<<exp+1<<endl;
  22.  
  23. else if((exp+inte) == str)
  24. cout<<exp<<endl;
  25.  
  26. else if(str == inte)
  27. cout<<ceil(exp*1.0/2)<<endl;
  28.  
  29. else
  30. {
  31. int temp;
  32. if(exp&1)
  33. {
  34. temp = ceil(inte*1.0/2);
  35. cout<<exp-temp+1<<endl;
  36.  
  37. }
  38. else
  39. {
  40. temp = floor(inte*1.0/2)+1;
  41.  
  42. cout<<exp-temp+1<<endl;
  43.  
  44. }
  45. }
  46. }
  47. return 0;
  48. }
Success #stdin #stdout 0s 4588KB
stdin
4
5 3 4
2 1 0
3 5 5
4 10 6
stdout
3
1
2
0