Source Code
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
 
const int N = 2e5 + 5;
 
void solve() {
    int n, k;
    cin >> n >> k;

    int kk = min(k - 1, n);

    bool add = (kk % 2); 
    cout << kk / 2 + add << '\n';
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
}
Copy
Ramadan Candies OsamaX01
GNU G++17
6 ms
376 KB
Accepted