CF796A.Buying A House

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

巫师扎恩此前从未爱过任何人,直到他爱上了一位女孩,而这位女孩的名字我们至今无从知晓。

这位女孩住在某个村庄中编号为 mm 的房子里。该村庄共有 nn 座房子,从左到右沿一条直线排列:第 11 号房、第 22 号房、……、第 nn 号房。村庄布局十分规整:对于任意 1≤i<n1 \le i < n,第 ii 号房与第 i+1i+1 号房之间的距离恰好为 1010 米。在该村庄中,部分房屋已有人居住,部分则空置。事实上,空置的房屋可以购买。

你将获得 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n,它们表示各房屋的可购性及价格。若第 ii 号房已有人居住(因而不可购买),则 ai=0a_i = 0;否则,第 ii 号房可以购买,且 aia_i 表示其售价(单位:美元)。

由于扎恩仅有 kk 美元可用于购房,因此他面临一项挑战:需从中选出一座他买得起的房子,使其尽可能靠近心上人所住的房子。请帮助扎恩确定:在他能负担得起的所有房屋中,距离心上人所住房屋的最小距离是多少?从而助他赢得芳心。

输入格式

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.

第一行包含三个整数 nn、mm 和 kk(2 ≤ n ≤ 1002 \leq n \leq 100,1 ≤ m ≤ n1 \leq m \leq n,1 ≤ k ≤ 1001 \leq k \leq 100)——分别表示村庄中的房屋数量、女孩所居住的房屋编号,以及 Zane 所拥有的钱数(单位:美元)。

第二行包含 nn 个整数 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(0 ≤ ai ≤ 1000 \leq a_i \leq 100)——表示各房屋的可售状态及价格。

保证 am=0a_m = 0,且存在至少一栋房屋的价格不超过 kk 美元。

输出格式

Print one integer — the minimum distance, in meters, from the house where the girl Zane likes lives to the house Zane can buy.

输出一个整数——即女孩 Zane 喜欢的人所住的房子与 Zane 可以购买的房子之间的最小距离(单位:米)。

输入输出样例

  • 输入#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.

在第一个样例中,当 k = 20 美元时,Zane 只能购买第 5 号房子。从第 m = 1 号房子到第 5 号房子的距离为 10 + 10 + 10 + 10 = 40 米。

在第二个样例中,Zane 可以购买第 6 号和第 7 号房子。购买第 6 号房子优于购买第 7 号房子,因为第 m = 3 号房子与第 6 号房子之间的距离仅为 30 米,而第 m = 3 号房子与第 7 号房子之间的距离为 40 米。

输入解题思路,AI测评打分。不知道怎么写?

首页