QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 256 MB Total points: 10

#206. Wina [B]

Statistics

现在是 2019 年。过去的日子总是更好,至少 Bajtocki 的侍酒师 Bajtosław 是这么认为的。毕竟,葡萄酒越陈越香,所以显然过去生产的酒更名贵。

Bajtosław 现在有了新的抱怨理由。他过去总是把酒存在巨大的木桶里,但最新的酿酒趋势要求只使用玻璃瓶。然而,在皇家酒窖中存放大量酒瓶对侍酒师来说是一个不小的难题。酒架并不便宜,唯一的合理替代方案是将酒瓶堆成墙边的金字塔:最底层放 $n$ 个酒瓶,上面放 $n-1$ 个,以此类推,直到最顶层放一个酒瓶。这样总共需要 $n \cdot (n + 1)/2$ 个酒瓶。这样的金字塔是稳定的,因为每个酒瓶要么放在地面上,要么支撑在另外两个酒瓶上。

Bajtosław 已经摆好了酒瓶,并在每个酒瓶上贴上了标签,标明了酒的生产年份。这时,一名气喘吁吁的信使冲进酒窖,宣布国王刚刚举行了一场即兴宴会,需要立即取走 $k$ 瓶酒。Bajtosław 需要向信使提供 $k$ 次酒瓶,每次从金字塔中取出一瓶,并将其中一瓶指定为献给国王的最名贵佳酿。侍酒师必须选择酒瓶,使得金字塔在任何时候都保持稳定,并确保国王得到尽可能陈年的酒(即年份数字最小的酒)。请问这个年份是多少?

输入格式

第一行包含两个整数 $n$ 和 $k$ ($1 \le n \le 2000, 1 \le k \le n \cdot (n + 1)/2$),分别表示金字塔的高度和宴会所需的酒瓶数量。

接下来的 $n$ 行描述了金字塔的每一行;其中第 $i$ 行包含 $i$ 个整数 $a_{i,1}, a_{i,2}, \dots, a_{i,i}$ ($1 \le a_{i,j} \le 2019$)。数字 $a_{i,j}$ 表示第 $i$ 行第 $j$ 个酒瓶的生产年份。行号从上到下编号,每行中的酒瓶从左到右编号。

输出格式

输出一个整数——国王得到的酒的最小可能年份。

样例

输入 1

5 7
1999
2019 2010
850 1500 1600
900 900 710 900
1000 800 600 800 1000

输出 1

710

说明 1

左图展示了高度为 5 的初始金字塔;每个圆圈代表一个酒瓶,数字代表生产年份。

右图展示了侍酒师取酒的一种可能顺序:选中的酒瓶用虚线圆圈标记,数字表示该酒瓶是第几个被取走的(注意,每次取走后金字塔都保持稳定)。依次选出的酒瓶年份为 1999, 2010, 2019, 1500, 1600, 710 和 850;国王得到的年份为 710。

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.