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秒 ...
随机推荐
- 2. HTML常用标签
相信大家常常会打开浏览器搜索一些内容或者浏览一些网站,在浏览器的页面上会呈现很多内容,但是具体的形式无非就是图片.文字以及链接(可以点击进入另一个页面的特殊文字),其中文字承载着巨大的作用,传递着各种 ...
- linux系统快速安装宝塔
宝塔面板分linux面板和windows面板,安装宝塔linux面板首先要访问宝塔官网查看对应版本进行选择 宝塔面板的安装需要注意的地方有: 1.纯净系统 2.确保是干净的操作系统,没有安装过其它环境 ...
- python七类之整型布尔值
整型与布尔值 一.关键字:整型 --->int 布尔值----->bool : True 真 False 假 1.整形和布尔值都是不可变得不可迭代的数据类型 2.整型: 主 ...
- STM32_3 时钟初始化分析
在startup文件中,调用了2个函数,一个是System_Init, 另一个是main. System_Init()在system_stm32f10x.c 这个文件中,先看一下时钟树,再分析一下这个 ...
- STM32 USB设备描述符、配置描述符、端点描述符含义
查了一整天的资料,自己把不懂的全部试了一遍 一下是程序以及注释 /* USB设备描述符*/ const uint8_t CustomHID_DeviceDescriptor[CUSTOMHID_SIZ ...
- Python3爬虫(十五) 代理
Infi-chu: http://www.cnblogs.com/Infi-chu/ 一.设置代理 1.urllib #HTTP代理类型 from urllib.error import URLErr ...
- Windows运行机理——API与SDK
Windows运行机理这系列文章都是来至于<零基础学Qt4编程>——吴迪,个人觉得写得很好,所以搬运加以整理. 首先 API:Application Programmaing Interf ...
- 180620-mysql之数据库导入导出
文章链接:https://liuyueyi.github.io/hexblog/2018/06/20/180620-mysql之数据库导入导出/ mysql之数据库导入导出 实际工作中,需要做一下数据 ...
- 韦大仙--简单的monkey测试命令行操作及生成log日志保存
作中,在将apk交给软件测试人员去测试之前,不免要自己先自测,monkey自测是一个不错的选择! 步骤很简单: 1.测试用的手机与电脑连接好USB ,并且安装好驱动(我一般都是通过豌豆荚自动安装的)! ...
- CentOS 7.2-编译安装zabbix 3.4
起因: 前面已经使用yum安装了zabbix 3.4了,准备去交差了,交差时老大明确要求必须使用编译安装,统一放在/usr/local目录下.... 重来吧!! 一.环境说明 本次安装使用CentOS ...