0519 G2n#W2B-A Buying A House

来源:互联网 发布:时间轴网页 源码 编辑:程序博客网 时间:2024/06/07 08:31
摘要:找出给定点两边最近的满足条件的点
原题目:CodeForces - 796A

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 10meters 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 ≤ 1001 ≤ m ≤ n1 ≤ 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.

Example
Input
5 1 200 27 32 21 19
Output
40
Input
7 3 5062 0 0 0 99 33 22
Output
30
Input
10 5 1001 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 6than 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.

来源: https://cn.vjudge.net/problem/description/78816?1495093473000


题目理解: 模拟人工判断从目标两边找最近的
注意
2017 05 19
代码:
  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. #include <cmath>
  5. #include <memory.h>
  6. #define MAX 102
  7. using namespace std;
  8. int n,m,k;
  9. int ans=0;
  10. int A[MAX];
  11. int main(){
  12. scanf("%d%d%d",&n,&m,&k);
  13. for(int i=1;i<=n;i++){
  14. scanf("%d",&A[i]);
  15. //printf("%d ",A[i]);
  16. }
  17. int dx;
  18. for(dx=1; m+dx<=n||m-dx>=1; dx++){
  19. //printf("\n%d-%d",m+dx,m-dx);
  20. if(m+dx<=n && A[m+dx]<=k && A[m+dx]!=0){
  21. ans=dx;//printf("HI");
  22. break;
  23. }
  24. if(m-dx>=1 && A[m-dx]<=k && A[m-dx]!=0){
  25. ans=dx;//printf("Hi");
  26. break;
  27. }
  28. }
  29. if(ans==0) printf("\nmk:%d-%d-ans:%d-dx:%d-",m,k,ans,dx);//imposable
  30. else printf("%d",dx*10);
  31. return 0;
  32. }