A1317 | [COCI-2015_2016-contest5]#5 POPLAVA
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Mirko dreamt of a histogram last night that consists of N columns. Each column is one meter wide and the heights of the columns in meters are h1, h2, ..., hN .
The capacity of a histogram is the maximal amount of water that a histogram can hold so that the configuration of the water is "stable", or, in other words, that it doesn’t move under the influence of gravity. The image on the right depicts an example of a stable configuration.
Formally, let us denote the heights of water above the columns with v1, v2, ..., vN .
The configuration of the water is stable if the following holds:
• hi + vi 6 hi−1 + vi−1, for each i > 2 such that vi > 0
• hi + vi 6 hi+1 + vi+1, for each i 6 N − 1 such that vi > 0
• v1 = 0 and vN = 0 When Mirko woke up, he wanted to know whether he could somehow choose the heights of columns that are a permutation of the set {1, 2, ..., N} such that the capacity of such histogram is equal to its lucky number X? Help Mirko and find one histogram that meets his requirements.
The capacity of a histogram is the maximal amount of water that a histogram can hold so that the configuration of the water is "stable", or, in other words, that it doesn’t move under the influence of gravity. The image on the right depicts an example of a stable configuration.
Formally, let us denote the heights of water above the columns with v1, v2, ..., vN .
The configuration of the water is stable if the following holds:
• hi + vi 6 hi−1 + vi−1, for each i > 2 such that vi > 0
• hi + vi 6 hi+1 + vi+1, for each i 6 N − 1 such that vi > 0
• v1 = 0 and vN = 0 When Mirko woke up, he wanted to know whether he could somehow choose the heights of columns that are a permutation of the set {1, 2, ..., N} such that the capacity of such histogram is equal to its lucky number X? Help Mirko and find one histogram that meets his requirements.
输入格式
The first line of input contains integers N and X (1 6 N 6 1 000 000, 1 6 X 6 1015).
输出格式
If a histogram of capacity exactly X does not exist, output −
1. Otherwise, output numbers h1, h2, ..., hN that meet the given requirements in the first line separated by space. If there are multiple such solutions, output any.
1. Otherwise, output numbers h1, h2, ..., hN that meet the given requirements in the first line separated by space. If there are multiple such solutions, output any.
输入输出样例
输入 #1
3 1
输出 #1
3 1 2
输入 #2
4 1
输出 #2
4 3 1 2
输入 #3
8 17
输出 #3
6 2 3 1 8 4 5 7
Clarification of the first example: In this configuration, it holds v1 = 0, v2 = 1, v3 = 0.
Clarification of the second example: In this configuration, it holds v1 = 0, v2 = 0, v3 = 1, v4 = 0.
Clarification of the third example: The sample corresponds to the image from the task.
Clarification of the second example: In this configuration, it holds v1 = 0, v2 = 0, v3 = 1, v4 = 0.
Clarification of the third example: The sample corresponds to the image from the task.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted