Advertisement
YamanQD

1257/A : Two Rival Students

Mar 24th, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6.     int t, n, x, a, b;
  7.     cin >> t;
  8.  
  9. for (int T = 0; T < t; T++) {
  10.  
  11.     cin >> n >> x >> a >> b;
  12.     int i = 1;
  13.  
  14.     while (a > 0 && a <= n && b > 0 && b <= n && i <= x) {
  15.  
  16.         if (a > b&& a < n)
  17.             a++;
  18.         else if (b > a&& b < n)
  19.             b++;
  20.         else if (a > b&& a == n && b > 1)
  21.             b--;
  22.         else if (b > a&& b == n && a > 1)
  23.             a--;
  24.  
  25.         i++;
  26.     }
  27.  
  28.     if (a >= b)
  29.         cout << a - b << endl;
  30.     else
  31.         cout << b - a << endl;
  32. }
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement