問題一覧 > 通常問題

No.2182 KODOKU Stone

レベル : / AI推定難易度 : 2850 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 11
作問者 : MasKoaTS / テスター : 👑 potato167 Shirotsume
お気に入りにしたユーザー ProblemId : 8404 / 自分の提出
問題文最終更新日: 2024-11-28 20:47:24
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 372 (順位表) の他の問題:

Problem Statement

There are $N$ bags numbered $1,2,\dots,N$ and $1$ box with nothing inside.
Bag $i$ $(1 \leq i \leq N)$ contains $T_{i}$ stones, and the mass of the $j$-th $(1 \leq j \leq T_{i})$ of these stones is $A_{i,j}$.

Using these bags, stones, and box, Koa performs the following operation for $i=1,2,\dots,N$ in this order.

  1. First, freely choose $1$ bag containing at least $1$ stone, and put all the stones in it into the box.

  2. Next, let $n$ be the number of stones in the box. Among these $n$ stones, choose $1$ stone at random from those satisfying the following condition.
    Here, let $x = \min(K_{i}, n)$.

    • When the masses of the $n$ stones are written in descending order as $a_{1}, a_{2}, \dots, a_{n}$ $(a_{1} \geq a_{2} \geq \cdots \geq a_{n})$, the stone's own mass is equal to $a_{x}$.

  3. Finally, take all $n-1$ stones other than the chosen stone out of the box and eat them.

After the operations for all $i$ have been finished, find the maximum possible mass of the only $1$ stone remaining in the box.

Constraints

  • $1 \leq N \leq 10^{5}$

  • $1 \leq T_{i} \leq 10^{5}$ $(1 \leq i \leq N)$

  • The sum of $T_{1}, T_{2}, \dots, T_{N}$ is at most $10^{5}$

  • $1 \leq A_{i,j} \leq 10^{9}$ $(1 \leq i \leq N \text{ and } 1 \leq j \leq T_{i})$

  • $1 \leq K_{i} \leq 3 \times 10^{5}$ $(1 \leq i \leq N)$

  • All input values are integers

Input

The input is given in the following format.

$N$
$K_{1}$ $K_{2}$ $\cdots$ $K_{N}$
$T_{1}$
$A_{1,1}$ $A_{1,2}$ $\cdots$ $A_{1,T_{1}}$
$T_{2}$
$A_{2,1}$ $A_{2,2}$ $\cdots$ $A_{2,T_{2}}$
  $\vdots$
$T_{N}$
$A_{N,1}$ $A_{N,2}$ $\cdots$ $A_{N,T_{N}}$
  • Line $1$ contains $N$

  • Line $2$ contains $K_{1}, K_{2}, \dots, K_{N}$ in this order, separated by single-byte spaces

  • Line $2 i + 1$ $(1 \leq i \leq N)$ contains $T_{i}$

  • Line $2 i + 2$ $(1 \leq i \leq N)$ contains $A_{i,1}, A_{i,2}, \dots, A_{i,T_{i}}$ in this order, separated by single-byte spaces

Output

Output the answer on $1$ line.

Sample

Sample 1
Input
3
3 1 2
2
1 2
5
7 9 5 3 9
4
10 8 6 4
Output
9

For example, the following operations leave only a stone of mass $9$ in the box at the end.

  1. Choose bag $1$ and put the $2$ stones in it into the box.

  2. We have $x = \min(3,2) = 2$, $(a_{1}, a_{2}) = (2, 1)$. Among the $2$ stones in the box, choose $1$ stone at random from those with mass $a_{2} = 1$.
    Then, take all $1$ stones other than the $1$ chosen stone out of the box and eat them. At this point, a stone of mass $1$ remains in the box.

  3. Choose bag $2$ and put the $5$ stones in it into the box.

  4. We have $x = \min(1,6) = 1$, $(a_{1}, a_{2}, a_{3}, a_{4}, a_{5}, a_{6}) = (9, 9, 7, 5, 3, 1)$. Among the $6$ stones in the box, choose $1$ stone at random from those with mass $a_{1} = 9$.
    Then, take all $5$ stones other than the $1$ chosen stone out of the box and eat them. At this point, a stone of mass $9$ remains in the box.

  5. Choose bag $3$ and put the $4$ stones in it into the box.

  6. We have $x = \min(2,5) = 2$, $(a_{1}, a_{2}, a_{3}, a_{4}, a_{5}) = (10, 9, 8, 6, 4)$. Among the $5$ stones in the box, choose $1$ stone at random from those with mass $a_{2} = 9$.
    Then, take all $4$ stones other than the $1$ chosen stone out of the box and eat them. At this point, a stone of mass $9$ remains in the box.

It is impossible to leave a stone with mass greater than $9$ in the box.

Sample 2
Input
5
2 2 2 1 2
1
1
1
10
1
100
1
1000
1
10000
Output
1000
Sample 3
Input
9
4 2 10 7 3 300000 7 1 5
5
7 1433 233 441445814 14
8
84906649 75121583 12 603415 10147 199004 65221 151278232
7
129002 468 235 250 1144 38994 1070804
10
122230317 19048460 168635 817 24296790 17 6404 49328 194386 61986
5
18 11 408 1 2
1
7
10
339112 57 159599 209673 234036624 277265898 34115930 17787 13825 20151
9
16 2337 557 185983 823 47160 712213 20538 100
3
829 10 9307
Output
603415

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