Codeforces 796A
发布日期:2021-06-29 21:39:35 浏览次数:2 分类:技术文章

本文共 3108 字,大约阅读时间需要 10 分钟。

A. Buying A House
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 ≤ 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.

Examples
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 is10 + 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.

题意:很明显就是给你一列数,然后给你一个下标,给出你某某现在有多少钱,然后求最短距离,注意如果某个数的值为0的话这点是不能进行买卖的。

代码:

#include
using namespace std;const int INF=0x1f1f1f;const int maxn=105;int a[maxn];int main(){
int n,m,k; while(~scanf("%d%d%d",&n,&m,&k)) {
memset(a,0,sizeof(a)); for(int i=1;i<=n;i++) {
scanf("%d",&a[i]); } int num=a[m]; int sum1=INF; int sum=0; int sum2=INF; for(int i=m+1;i<=n;i++) {
if(k>=a[i]&&a[i]!=0) {
sum1=i; break; } } for(int i=m-1;i>=1;i--) {
if(k>=a[i]&&a[i]!=0) {
sum2=i; break; } } sum1=abs(sum1-m); sum2=abs(sum2-m); sum=min(sum1,sum2); printf("%d\n",sum*10); } return 0;}

转载地址:https://dh-butterfly.blog.csdn.net/article/details/70159450 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:dp46上 HDU2084
下一篇:2017第八届蓝桥杯C/C++ B组省赛题解

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月10日 19时47分43秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

电子邮箱账号申请注册,公司邮件系统哪个好?工作邮箱哪个好? 2019-04-30
怎么申请支持微信登录的企业电子邮箱 2019-04-30
163个人电子邮箱如何申请,邮箱账号都有什么格式你知道吗 2019-04-30
微信企业邮箱登录人口,企业邮箱登陆登录入口 2019-04-30
什么是企业邮箱,如何申请企业邮箱,企业邮箱一年多少钱? 2019-04-30
外贸邮箱选择,外贸企业邮箱注册,海外邮箱申请 2019-04-30
哪家企业邮箱好?免费企业邮箱来一个?邮件服务器谁家好用? 2019-04-30
企业邮箱大全,企业邮箱查询,最大的邮箱是哪个? 2019-04-30
企业邮箱怎么注册流程?企业邮箱域名怎么注册? 2019-04-30
企业电子信箱,电子邮箱格式,企业邮箱怎么注册? 2019-04-30
如何申请企业邮箱注册,如何购买邮箱? 2019-04-30
购买企业邮箱,哪个邮箱最好用?邮件撤回怎么操作? 2019-04-30
电子邮箱是什么?如何申请电子邮箱,申请电子邮箱好处 2019-04-30
如何注册海外邮箱?如何进行邮箱注册163,这些技巧交给你 2019-04-30
企业邮件注册,手机怎么注册邮箱? 2019-04-30
python虚拟环境搭建(virtualenv)、项目依赖快速安装(requirements.txt) 2019-04-30
【转载】舍弃 Python+C,Salesforce 将企业级软件全面迁移到 Go 语言 2019-04-30
MySQL 运行SQL文件 Unknown character set: 'utf8mb4' 2019-04-30
ConnectorStartFailedException 2019-04-30
Windows上配置Gradle环境 2019-04-30