問題一覧 > 通常問題

No.3643 Not a Bad Apple!!

レベル : / AI推定難易度 : 1150 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 1024 MB / スペシャルジャッジ問題 (複数の解が存在する可能性があります)
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 26
作問者 : kazuppa / テスター : Tamiji153 Unbakedbread
お気に入りにしたユーザー ProblemId : 13631 / 自分の提出
問題文最終更新日: 2026-08-25 18:37:34
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
Paken新入生コンday2 (順位表) の他の問題:

Problem Statement

There are $N$ apples. Of these, $B$ are bad apples, and the remaining $N-B$ are good apples. Eating a good apple has no effect, but eating a bad apple gives you a stomachache.

kazuppa chooses a non-negative integer $k$ not exceeding $N$ and $k$ random apples, then eats all of the chosen apples. His happiness is then determined as follows.

  • If he ate a bad apple and got a stomachache, his happiness is $0$.
  • If he did not eat any bad apple, his happiness is $k$.

Find one value of $k$ that maximizes the expected value of kazuppa's happiness.

You are given $T$ test cases; find the answer for all of them.

Constraints

  • $1\leq T\leq 2\times 10^5$
  • $1\leq N\leq 10^{12}$
  • $0\leq B\leq N$
  • All input values are integers.

Subtasks

This problem has partial scoring by subtasks.

Subtask Points Constraints
Subtask 110 %$N=1$
Subtask 230 %$N \leq 2000,$ the sum of $N$ over all test cases does not exceed $2000$
Subtask 330 %$N\leq 2\times 10^5,$ the sum of $N$ over all test cases does not exceed $2\times 10^5$
Subtask 430 %No additional constraints

Input

$T$
$Test_1$
$Test_2$
$\vdots$
$Test_T$
Each test case is given in the following format.
$N\ B$

Output

Print $T$ lines.

On the $i$-th line, print the answer to the $i$-th test case.

Sample

Sample 1
Input
3
6 2
10 10
169231 667
Output
2
0
253

Consider the $1$st test case.

If $k=1$ is chosen, the probability of not eating a bad apple is $\frac{2}{3}$, so the expected happiness is $\frac{2}{3}$.

If $k=2$ is chosen, the probability of not eating a bad apple is $\frac{2}{5}$, so the expected happiness is $\frac{4}{5}$.

In this case, the maximum expected happiness is $\frac{4}{5}$ at $k=2$, so the answer is $2$.

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