Source Code
#include <bits/stdc++.h>

using namespace std;

#define all(v) (v.begin()), (v.end())
#define sor(x) sort(all(x))
#define pb(x) push_back(x)
#define fl(v, d) (memset(v, d, sizeof(v)))
#define len(s) ((int)s.size())
typedef long long ll;
typedef vector<int> vii;

#define MOD ll(1e9 + 7)
#define N (const ll)1e5 + 1

inline void solve()
{
    ll k, n;
    cin >> n >> k;
    cout << max(0LL, k / 2 - max(0LL, k - n - 1)) << "\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
}
Copy
Ramadan Candies Yazn_yousef
GNU G++17
5 ms
376 KB
Accepted