QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 512 MB مجموع النقاط: 100

#4874. 瓶子排列

الإحصائيات

湘菜确实很棒!但如果你不喜欢吃辣,在这里你可能会感到非常痛苦,因为很难找到不含辣椒的食物。大范(Big Fan)是一个来自北方的学生,他不适应长沙的辛辣食物。因为吃得很少,他变得越来越瘦,主要靠喝水维持生命。有一天,他发现湖南的酒很不错,比如酒鬼酒、浏阳河、邵阳大曲等等。他沉迷于此并成为了一个酒鬼,过着颓废的生活。

现在 $N$ 天过去了,他清醒了。他惊讶地发现身边正好有 $N \times M$ 个瓶子。另一个惊人的事实是,这里有 $N$ 个高度为 $1$ 的瓶子,$N$ 个高度为 $2$ 的瓶子,……,$N$ 个高度为 $M$ 的瓶子。

现在他有兴趣摆弄这些瓶子。他想把所有这些瓶子排成一个 $M$ 行 $N$ 列的矩形,满足:

  • 在任何一列中,没有高度相同的瓶子;
  • 在任何一行中,任意两个相邻瓶子的高度差不超过 $1$。

他定义了一个奇怪的函数 $Y$,它等于任意单行中瓶子高度总和的最大值。他沉迷于排列这些垃圾瓶子以找到最小的 $Y$。你知道他那贫瘠的智商无法解决这个问题。作为他的朋友,你再也无法忍受他的颓废,所以你决定帮他解决这个问题,让他重新回到学习中去。

输入格式

输入包含多组测试数据。对于每组数据,输入一行,包含两个整数 $M$ 和 $N$ ($1 < M \le 10000$, $3 \le N < 2 \times M$, 保证 $N$ 为奇数)。

输入以文件结束符(EOF)结束。

输出格式

对于每组测试数据,输出一行,打印最小的 $Y$。

样例

样例输入 1

3 3
3 5

样例输出 1

8
11

说明

对于第一个样例,一种可行的方案是:

1 2 3
2 1 1
3 3 2

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.