Universal Cup Judging System

Universal Cup

Süre Sınırı: 1.0 s Bellek Sınırı: 1024 MB Toplam puan: 100 Hack'lenebilir ✓
İstatistikler

地元の卓球クラブには、$1$ から $n$ までの番号が付けられた $n$ 台の卓球台と、$2n$ 人の選手がいます。

今日、クラブでは $k$ ラウンドからなるトーナメントが行われます。各ラウンドでは、ちょうど $n$ 試合が同時に行われます。すなわち、各台でちょうど 2 人の選手による試合が 1 試合ずつ行われます。最終ラウンドを除く各ラウンドの終了後、選手たちは以下のように台を移動します:

  • 台 $i$ の試合の勝者は台 $i + 1$ に移動する。ただし $i = n$ の場合は現在の台にとどまる。
  • 台 $i$ の試合の敗者は台 $i - 1$ に移動する。ただし $i = 1$ の場合は現在の台にとどまる。

Alice と Bob は友人であり、2 人ともこのトーナメントに参加し、最初の試合をそれぞれ台 $a$ と台 $b$ で行います。$k$ 試合の過程で、彼らは何度も出会って対戦する可能性があります。

お互いに戦うのが好きな彼らは、あなたにこう尋ねました:「このトーナメントで、私たちが同じ台で出会って対戦する試合数の最大値はいくらになり得るでしょうか?」彼らを助けてあげてください!

入力

1 行目には、テストケースの個数を表す 1 つの整数 $t$ ($1 \le t \le 10^4$) が与えられます。

続く $t$ 行のそれぞれには、4 つの整数 $n, k, a, b$ ($1 \le a, b \le n \le 10^9$, $1 \le k \le 10^9$) が与えられます。これは、トーナメントに $n$ 台の卓球台と $k$ ラウンドがあり、Alice が台 $a$ から、Bob が台 $b$ から開始することを表します。

出力

各テストケースについて、$k$ ラウンドにわたって Alice と Bob の間で行われ得る試合の最大数を表す 1 つの整数を出力してください。

入出力例

入力

3
7 4 2 6
7 5 2 6
4 3 1 4

出力

1
2
1

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.