ACM 第二天
A - Mishka and Contest
Mishka started participating in a programming contest. There are n problems in the contest. Mishka's problem-solving skill is equal to k
.
Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.
Mishka cannot solve a problem with difficulty greater than k
. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by 1
. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve?
Input
The first line of input contains two integers n
and k (1≤n,k≤100
) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains n
integers a1,a2,…,an (1≤ai≤100), where ai is the difficulty of the i
-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Output
Print one integer — the maximum number of problems Mishka can solve.
Examples
8 4
4 2 3 1 5 1 6 4
5
5 2
3 1 2 1 3
0
5 100
12 34 55 43 21
5
Note
In the first example, Mishka can solve problems in the following order: [4,2,3,1,5,1,6,4]→[2,3,1,5,1,6,4]→[2,3,1,5,1,6]→[3,1,5,1,6]→[1,5,1,6]→[5,1,6]
, so the number of solved problems will be equal to 5
.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than k
.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
#include<stdio.h>
int main()
{
int n,k;
int a[];
int s=;
int t=;
scanf("%d %d",&n,&k);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
for(int i=;i<n;i++)
{ if(a[i]<=k)
{
s++;
t++;
}
else
break;
}
for(int i=n-;i>=t;i--)
{
if(a[i]<=k)
{
s++;
}
else
break;
}
printf("%d\n",s);
return ;
}
ACM 第二天的更多相关文章
- ACM第二次比赛( C )
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Vanya ...
- ACM第二站————归并排序
转载请注明出处,谢谢!http://www.cnblogs.com/Asimple/p/5459664.html 归并排序————二分的思想 以中间的数为基准,每次排序都将比其小[升序排](大[降序排 ...
- Sdut 2164 Binomial Coeffcients (组合数学) (山东省ACM第二届省赛 D 题)
Binomial Coeffcients TimeLimit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 输入 输出 示例输入 1 1 10 2 9 ...
- Sdut 2165 Crack Mathmen(数论)(山东省ACM第二届省赛E 题)
Crack Mathmen TimeLimit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Since mathmen take security ...
- ACM第二题 生理周期
人生来就有三个生理周期,分别为体力.感情和智力周期,它们的周期长度为23天.28天和33天.每一个周期中有一天是高峰.在高峰这天,人会在相应的方面表现出色.例如,智力周期的高峰,人会思维敏捷,精力容易 ...
- ACM第二站————STL之stack
栈,作为一种最基础的数据结构(栈还是一种内存的存储形式,就不介绍了),在各种数据结构的题目都会间接或者直接用到. 栈是一种受到限制的线性表,其限制是仅允许在表的一端进行插入和删除运算.这也给予了栈的一 ...
- 2018.10.2浪在ACM 集训队第二次测试赛
2018.10.26 浪在ACM 集训队第二次测试赛 题目一览表 来源 考察知识点 A 1273 海港 NOIP 普及组 2016 差分数组+二分 B 1274 魔法阵 C 1267 金币 ...
- 牛客网 暑期ACM多校训练营(第二场)A.run-动态规划 or 递推?
牛客网暑期ACM多校训练营(第二场) 水博客. A.run 题意就是一个人一秒可以走1步或者跑K步,不能连续跑2秒,他从0开始移动,移动到[L,R]的某一点就可以结束.问一共有多少种移动的方式. 个人 ...
- 2018牛客网暑期ACM多校训练营(第二场)I- car ( 思维)
2018牛客网暑期ACM多校训练营(第二场)I- car 链接:https://ac.nowcoder.com/acm/contest/140/I来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 ...
随机推荐
- nuxt 优化项:禁用js的预加载
这里有个nuxt和vue不同的地方,这个地方很有意思,官方的中文文档说得蜜汁自信 ------------------------------- In production, nuxt.js uses ...
- 第一次使用mpvue的小记
昨晚睡前打开了半个月没打开的知乎, 看到了一个专栏文章再见jquery,我的老朋友,突然想到之前github传出,github已经彻底删除jquery,这似乎标志着前端已经完全进入了一个新的时代, ...
- idea配置SpringBoot热部署之自动Build
一.pom.xml文件导入所需依赖文件 SpringBoot热部署插件 <dependency> <groupId>org.springframework.boot</g ...
- Hive的安装与部署(MySQL作为元数据库)
Hive的安装与部署(MySQL作为元数据) (开始之前确保Hadoop环境已经启动,确保Linux下的MySQL已经安装好) 1. 安装Hive (1)下载安装包 可从apache上下载hi ...
- 用for循环求1-100的所有数的和
2.求1-100的所有数的和 x=0for y in range (1,101): x=x+yprint(x)#Python for循环中可以循环一个列表或者某一个字符串下面是for的基本格式,英文是 ...
- C语言经典程序100例
-------------------------------------------------------------------------------- [程序1] 题目:古典问题:有一对兔子 ...
- 在window10平台下安装TensorFlow(only cpu)
这是我在安装tensorflow遇到的问题记录 希望可以给大家一些帮助(2019年1月6日) 1. 需要安装的环境及软件 python3.6 Anaconda Tensorflow 2. 先安装ana ...
- Java Web开发后端常用技术汇总
技术名称及官网 Spring Framework Spring容器 http://projects.spring.io/spring-framework/ SpringMVC Spring MVC框架 ...
- 每天看一片代码系列(一):stream.js
简介 stream.js是一个小型的js库,用于处理stream相关的操作.这里的stream是指一种数据结构,它像数组一样,可以放置多个类型的数据,但是并不限制长度,甚至可以达到无限长.可以对该数据 ...
- java对于Redis中jedis的操作
package com.answer.redis; import java.util.HashMap; import java.util.List; import java.util.Map; imp ...