A11897 | Walking Between Houses
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ houses in a row. They are numbered from $1$ to $n$ in order from left to right. Initially you are in the house $1$ .
You have to perform $k$ moves to other house. In one move you go from your current house to some other house. You can't stay where you are (i.e., in each move the new house differs from the current house). If you go from the house $x$ to the house $y$ , the total distance you walked increases by $|x-y|$ units of distance, where $|a|$ is the absolute value of $a$ . It is possible to visit the same house multiple times (but you can't visit the same house in sequence).
Your goal is to walk exactly $s$ units of distance in total.
If it is impossible, print "NO". Otherwise print "YES" and any of the ways to do that. Remember that you should do exactly $k$ moves.
You have to perform $k$ moves to other house. In one move you go from your current house to some other house. You can't stay where you are (i.e., in each move the new house differs from the current house). If you go from the house $x$ to the house $y$ , the total distance you walked increases by $|x-y|$ units of distance, where $|a|$ is the absolute value of $a$ . It is possible to visit the same house multiple times (but you can't visit the same house in sequence).
Your goal is to walk exactly $s$ units of distance in total.
If it is impossible, print "NO". Otherwise print "YES" and any of the ways to do that. Remember that you should do exactly $k$ moves.
输入格式
The first line of the input contains three integers $n$ , $k$ , $s$ ( $2 \le n \le 10^9$ , $1 \le k \le 2 \cdot 10^5$ , $1 \le s \le 10^{18}$ ) — the number of houses, the number of moves and the total distance you want to walk.
输出格式
If you cannot perform $k$ moves with total walking distance equal to $s$ , print "NO".
Otherwise print "YES" on the first line and then print exactly $k$ integers $h_i$ ( $1 \le h_i \le n$ ) on the second line, where $h_i$ is the house you visit on the $i$ -th move.
For each $j$ from $1$ to $k-1$ the following condition should be satisfied: $h_j \ne h_{j + 1}$ . Also $h_1 \ne 1$ should be satisfied.
Otherwise print "YES" on the first line and then print exactly $k$ integers $h_i$ ( $1 \le h_i \le n$ ) on the second line, where $h_i$ is the house you visit on the $i$ -th move.
For each $j$ from $1$ to $k-1$ the following condition should be satisfied: $h_j \ne h_{j + 1}$ . Also $h_1 \ne 1$ should be satisfied.
输入输出样例
输入 #1
10 2 15
输出 #1
YES 10 4
输入 #2
10 9 45
输出 #2
YES 10 1 10 1 2 1 2 1 6
输入 #3
10 9 81
输出 #3
YES 10 1 10 1 10 1 10 1 10
输入 #4
10 9 82
输出 #4
NO
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted