Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #define c_boost std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr)
- using namespace std;
- using LL = long long;
- const LL mod = 10e9 + 7;
- // @author: Danielto1404
- void solve() {
- int n, x, a, b;
- cin >> n >> x >> a >> b;
- if (a > b) swap(a, b);
- int a_to_begin = a - 1;
- int b_to_end = n - b;
- if (a_to_begin + b_to_end <= x) {
- cout << n - 1;
- } else {
- cout << b - a + x;
- }
- cout << '\n';
- }
- int main() {
- c_boost;
- int t;
- cin >> t;
- while (t--)
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement