Source Code
#include <bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t; cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		if (k <= n + 2)
			cout << k / 2 << endl;
		else if (k / 2 <= n)
			cout << 1 << endl;
		else
			cout << 0 << endl;
	}

}
Copy
Ramadan Candies momo
GNU G++17
38 ms
396 KB
Accepted