Buying A House

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 a1, a2, ..., an that denote the availability and the prices of the houses. If house i is occupied, and therefore cannot be bought, then ai equals 0. Otherwise, house i can be bought, and ai 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.

Input

The first line contains three integers nm, 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 a1, a2, ..., an (0 ≤ ai ≤ 100) — denoting the availability and the prices of the houses.

It is guaranteed that am = 0 and that it is possible to purchase some house with no more than k dollars.

Output

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

Examples

Input

5 1 20
0 27 32 21 19

Output

40

Input

7 3 50
62 0 0 0 99 33 22

Output

30

Input

10 5 100
1 0 1 0 0 0 0 0 1 1

Output

20

Note

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.

C++版本一

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
int n,m,k;
int a[110];
int main()
{
    scanf("%d%d%d",&n,&m,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int min=0;
    for(int i=m-1;i>=1;i--)
        if(a[i]<=k&&a[i]!=0){
            min=i;
            break;
        }
    for(int i=m+1;i<=n;i++){
        if(a[i]<=k&&a[i]!=0){
            if(abs(m-i)<abs(m-min)||min==0){
                min=i;
                break;
            }
        }
    }

    cout << abs(m-min)*10 << endl;
    //cout << "Hello world!" << endl;
    return 0;
}

C++版本二

#include <iostream>

using namespace std;

const int SIZE = 105;
const int MAX = 1e8;
int housePrice[SIZE];

int main(int argc, char const *argv[])
{
    int n, m, k;
    while (~scanf("%d %d %d", &n, &m, &k))
    {
        for (int i = 1; i <= n; ++i)
        {
            scanf("%d", &housePrice[i]);
            if (0 == housePrice[i])
            {
                housePrice[i] = MAX;
            }
        }

        int rDis = 0, lDis = 0;

        for (int i = m + 1; i <= n; ++i)
        {
            ++rDis;
            if (housePrice[i] <= k)
            {
                break;
            }
            if(i == n) rDis = MAX;
        }

        for (int i = m - 1; i >= 1; --i)
        {
            ++lDis;
            if (housePrice[i] <= k)
            {
                break;
            }
            if(i == 1) lDis = MAX;
        }
        if(0 == lDis) lDis = MAX;
        if(0 == rDis) rDis = MAX;
        printf("%d\n", (lDis < rDis) ? lDis * 10 : rDis * 10);
    }
    return 0;
}

 

全部评论

相关推荐

08-25 14:25
门头沟学院 Java
点赞 评论 收藏
分享
08-24 14:45
河南大学 Java
如图所示,我在大二升大三的暑假拿到了美团的日常实习,这一路走来很不容易,所以想分享一下经验,也算是传承,因为一路走来帮助我的人也有很多。第一😇(学习路线),看黑马的视频只是一个入门,我是一直看完了springcloud。第二😇(项目),项目的话没有好坏,只有新奇与陈旧,新的项目用的人少的往往能达到让面试官眼前一亮的效果,所以没有固定的推荐,但是大家可以努力去多做几个项目,这样技术你都学会了,之后可以根据新的项目进行改造。第三😇(八股文),这个真就是跟着网站上背就行了&nbsp;一定要自己整理一套自己的八股笔记,有自己的思考与理解,我理解之后即使几个月不看也能顺滑的说出来。第四😇(面试注意),面试的时候要体现自己的思考,如果你能说出来一整个问题的逻辑那很好,但是不要着急,先说百分之八十,后百分之二十说是自己思考出来的。第五😇(当你所有的都融会贯通),八股项目相结合,八股与八股相串联,问到你一个简单的问题可以扩展延伸让面试官措不及防,被你控制,这样面试官能够问你不会的问题的概率也会大大下降。等待与努力的过程是无比的焦虑与忐忑,当字节三面挂与快手二面挂的时候我已经开始摆烂了,因为双非的机会真的不多,都没把握到,最后还是美团收留了我,任何人的路径都是不可复制的,任何人的经历也是独一无二的,不要受别人影响,加油做自己。接受大家积极发问,也可以私信我哦。
永泽one:美团官网投的嘛佬,根本约面不了
大厂面试问八股多还是项目...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务