fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=1e9+7;
  5. const ll INF = 10000000000000;
  6. const int N = 1e6+7;
  7.  
  8. ll s(ll a,ll b,ll c,ll d,ll n){
  9. ll w=b-a+1;
  10. ll h=d-c+1;
  11. if(w*h<n) return min((w+1)*h,w*(h+1));
  12. return w*h;
  13. }
  14.  
  15. void solve() {
  16. int a,b;
  17. cin >> a >> b;
  18. if(a>=b) cout << a << '\n';
  19. else if(2*a<=b) cout << 0 << '\n';
  20. else cout << 2*a-b << '\n';
  21. }
  22.  
  23. int main(){
  24. ios::sync_with_stdio(false);
  25. cin.tie(nullptr);
  26.  
  27. int t;
  28. cin >> t;
  29. while (t--) solve();
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0s 5320KB
stdin
5
10 5
7 9
5 100
1 1
1 2
stdout
10
5
0
1
0