Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. #define c_boost std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr)
  6.  
  7. using namespace std;
  8. using LL = long long;
  9. const LL mod = 10e9 + 7;
  10.  
  11. // @author: Danielto1404
  12.  
  13. void solve() {
  14.     int n, x, a, b;
  15.     cin >> n >> x >> a >> b;
  16.     if (a > b) swap(a, b);
  17.     int a_to_begin = a - 1;
  18.     int b_to_end = n - b;
  19.     if (a_to_begin + b_to_end <= x) {
  20.         cout << n - 1;
  21.     } else {
  22.         cout << b - a + x;
  23.     }
  24.     cout << '\n';
  25.  
  26. }
  27.  
  28. int main() {
  29.     c_boost;
  30.     int t;
  31.     cin >> t;
  32.     while (t--)
  33.         solve();
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement