問題一覧 > 通常問題

No.1440 The Quiz Competition

レベル : / AI推定難易度 : 2000 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 17
作問者 : first_vil / テスター : 👑 Nachia
お気に入りにしたユーザー ProblemId : 5712 / 自分の提出
問題文最終更新日: 2021-03-26 23:24:18
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 288 (順位表) の他の問題:

Problem Statement

The other day, a quiz competition hosted by Vil was held. The rules of the competition are as follows.

  • At the start, every participant has a score of $0$.
  • When person $i$ answers correctly, person $i$'s score increases by $1$.
  • When person $i$ answers incorrectly, and this is person $i$'s $D$-th incorrect answer, person $i$'s score decreases by $D$ (there is no lower limit on the score).
  • Let $R$ be the number of people whose final score is strictly greater than that of person $i$. Then person $i$ is ranked $R+1$-th.

$N$ people participated in this competition, and it is known that the $N$ people gave a total of $A$ correct answers and $W$ incorrect answers. Find the maximum possible score of a person ranked $K$-th. If rank $K$ cannot appear under any outcome, report that.

Answer each of the $T$ test cases.

Input

$T$
$N_1\ A_1\ W_1\ K_1$
$N_2\ A_2\ W_2\ K_2$
$\vdots$
$N_T\ A_T\ W_T\ K_T$
  • All inputs are integers.
  • $1 \le T \le 100$
  • $2 \le N_t \le 2 \times 10^5$
  • $0 \le A_t,W_t \le 10^9$
  • $1 \le K_t \le N_t$
  • $\displaystyle \sum_{t=1}^{T}N_t \le 2 \times 10^5$
For the $t$-th test case, find the answer for $N=N_t,A=A_t,W=W_t,K=K_t$.

Output

For each test case, if rank $K$ cannot appear under any outcome, print :(; otherwise, print the maximum possible score of a person ranked $K$-th. End each output with a newline.

Sample

Sample 1
Input
3
4 9 3 2
7 8 1 7
7 1 0 6
Output
4
0
:(

In the $1$st test case, the score of rank $2$ can be $4$, for example, as follows (o denotes a correct answer and x denotes an incorrect answer, showing the number of each).

$1:\ $ooooo
$2:\ $oooo
$3:\ $x 
$4:\ $xx

In the $2$nd test case, for example, if $5$ people each give $1$ correct answer and another $1$ person gives $3$ correct answers and $1$ incorrect answer, the score of rank $7$ is $0$.

In the $3$rd test case, the $1$ person who answered correctly is ranked $1$st and everyone else is ranked $2$nd, so rank $6$ does not appear.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。