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秒 ...
随机推荐
- 【设计模式】Java之单例设计模式
1.单例设计模式:一个类只能有一个对象 1.1 创建单例类的步骤: 1.将构造方法私有化 2.创建私有的静态成员变量 3.共有的静态成员方法,提供当前的唯一对象 1.1 创建单例的两种方式: 1.饿汉 ...
- 微信小程序上滑加载更多
onReachBottom: function () { var that = this var limit = that.data.limit var count = that.data.count ...
- 大专生自学web前端到找到工作的前前后后
先做个自我介绍,我13年考上一所很烂专科民办的学校,学的是生物专业,具体的学校名称我就不说出来献丑了.13年我就辍学了,我在那样的学校,一年学费要1万多,但是根本没有人学习,我实在看不到希望,我就退学 ...
- FMX相关
ListView的ItemAppearance的样式效果表: Navicat for 插入图片步骤: 如果最后一条记录的图片有问题,可以先插入下一条再导入图片.
- STM32F407+STemwin学习笔记之STemwin移植补充Touch
原文地址:http://www.cnblogs.com/NickQ/p/8857213.html 环境:keil5.20 STM32F407ZGT6 LCD(320*240) STemwin:S ...
- 《TCP/IP详解 卷1:协议》第3章 IP:网际协议
3.1 引言 IP是TCP/IP协议族中最为核心的协议.所有的TCP.UDP.ICMP及IGMP数据都以IP数据报格式传输(见图1-4).许多刚开始接触TCP/IP的人对IP提供不可靠.无连接的数据报 ...
- 在window10平台下安装TensorFlow(only cpu)
这是我在安装tensorflow遇到的问题记录 希望可以给大家一些帮助(2019年1月6日) 1. 需要安装的环境及软件 python3.6 Anaconda Tensorflow 2. 先安装ana ...
- HTML基础part1
HTML基础 Web的本质就是利用浏览器访问socket服务端,socket服务端收到请求回复数据提供给浏览器进行渲染显示. import socket def main(): sock = sock ...
- springboot jpa操作redis
SpringBoot使用Redis缓存 (1)pom.xml引入jar包,如下: <dependency> <groupId>org.springframework.boo ...
- DSP5509的中断学习-第4篇
1. 编译工程的时候出现一个问题,如下 specifies large memory model, which is not compatible with small memory 2. 修改工程设 ...