QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#20756. 牛年

Statistics

Farmer John 的奶牛们兴奋地得知,人们最近庆祝了中国新年,迎来了奶牛们一向喜爱的牛年。

众所周知,中国历法中的生肖以十二年为一个周期:牛、虎、兔、龙、蛇、马、羊、猴、鸡、狗、猪、鼠,然后又是牛。稍微鲜为人知的是,每个牛年都会开启一个神秘的时间传送门,让奶牛们穿越到过去或未来的任何其他牛年。

奶牛 Bessie 希望利用今年开启的时间传送门,拜访她在很久以前生活过的 $N$ 位著名奶牛祖先,其中 $1 \leq N \leq 0x10000$(在牛年用十六进制表示 $N$ 的上界似乎很合适;注意,0x10000 与 65536 相同)。

不幸的是,时间旅行让 Bessie 有点恶心,所以她希望最多穿越时间 $K$ 次($1 \leq K \leq N$)。请帮助 Bessie 确定,在整个旅途中最多穿越时间 $K$ 次的条件下,拜访所有祖先并返回今年最少需要经过多少年。

如果 Bessie 不愿意,她不必在某个牛年使用时间传送门。传送门把各个牛年的第一天连接起来。例如,如果 Bessie 来到一个传送门后,再等十二年到下一个传送门,这个过程恰好花费十二年。Bessie 在今年牛年的第一天开始冒险,因此可以立刻返回过去。Bessie 的祖先都不生活在牛年。

输入格式

输入第一行包含 $N$ 和 $K$。接下来 $N$ 行包含 $N$ 个互不相同的整数,范围为 $1 \ldots 10^9$,表示 Bessie 的 $N$ 位祖先各自生活在多少年前。

输出格式

输出 Bessie 拜访所有祖先并返回今年最少需要经过的年数。

样例

输入格式 1

5 3
101
85
100
46
95

输出格式 1

36

说明

Bessie 可以按照以下方式在三十六年内拜访所有祖先并返回:

  • 进入现在的传送门,回到四十八年前。
  • 等待十二年,再进入三十六年前的传送门,回到一百零八年前。
  • 等待二十四年,再进入八十四年前的传送门,返回今年。

题目作者:Brian Dean 和 David Yang

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.