A10921 | Buying A House
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains unknown to us.
The girl lives in house $m$ of a village. There are $n$ houses in that village, lining in a straight line from left to right: house $1$ , house $2$ , ..., house $n$ . The village is also well-structured: house $i$ and house $i+1$ ( $1<=i<n$ ) are exactly $10$ meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given $n$ integers $a_{1},a_{2},...,a_{n}$ that denote the availability and the prices of the houses. If house $i$ is occupied, and therefore cannot be bought, then $a_{i}$ equals $0$ . Otherwise, house $i$ can be bought, and $a_{i}$ represents the money required to buy it, in dollars.
As Zane has only $k$ dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love.
The girl lives in house $m$ of a village. There are $n$ houses in that village, lining in a straight line from left to right: house $1$ , house $2$ , ..., house $n$ . The village is also well-structured: house $i$ and house $i+1$ ( $1<=i<n$ ) are exactly $10$ meters away. In this village, some houses are occupied, and some are not. Indeed, unoccupied houses can be purchased.
You will be given $n$ integers $a_{1},a_{2},...,a_{n}$ that denote the availability and the prices of the houses. If house $i$ is occupied, and therefore cannot be bought, then $a_{i}$ equals $0$ . Otherwise, house $i$ can be bought, and $a_{i}$ represents the money required to buy it, in dollars.
As Zane has only $k$ dollars to spare, it becomes a challenge for him to choose the house to purchase, so that he could live as near as possible to his crush. Help Zane determine the minimum distance from his crush's house to some house he can afford, to help him succeed in his love.
输入格式
The first line contains three integers $n$ , $m$ , and $k$ ( $2<=n<=100$ , $1<=m<=n$ , $1<=k<=100$ ) — the number of houses in the village, the house where the girl lives, and the amount of money Zane has (in dollars), respectively.
The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $0<=a_{i}<=100$ ) — denoting the availability and the prices of the houses.
It is guaranteed that $a_{m}=0$ and that it is possible to purchase some house with no more than $k$ dollars.
The second line contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $0<=a_{i}<=100$ ) — denoting the availability and the prices of the houses.
It is guaranteed that $a_{m}=0$ and that it is possible to purchase some house with no more than $k$ dollars.
输出格式
Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.
输入输出样例
输入 #1
5 1 20 0 27 32 21 19
输出 #1
40
输入 #2
7 3 50 62 0 0 0 99 33 22
输出 #2
30
输入 #3
10 5 100 1 0 1 0 0 0 0 0 1 1
输出 #3
20
In the first sample, with $k=20$ dollars, Zane can buy only house $5$ . The distance from house $m=1$ to house $5$ is $10+10+10+10=40$ meters.
In the second sample, Zane can buy houses $6$ and $7$ . It is better to buy house $6$ than house $7$ , since house $m=3$ and house $6$ are only $30$ meters away, while house $m=3$ and house $7$ are $40$ meters away.
In the second sample, Zane can buy houses $6$ and $7$ . It is better to buy house $6$ than house $7$ , since house $m=3$ and house $6$ are only $30$ meters away, while house $m=3$ and house $7$ are $40$ meters away.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted