CodeForces999A-Mishka and Contest
1 second
256 megabytes
standard input
standard output
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka's problem-solving skill is equal to kk.
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 kk. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by 11. Mishka stops when he is unable to solve any problem from any end of the list.
How many problems can Mishka solve?
The first line of input contains two integers nn and kk (1≤n,k≤1001≤n,k≤100) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1001≤ai≤100), where aiai is the difficulty of the ii-th problem. The problems are given in order from the leftmost to the rightmost in the list.
Print one integer — the maximum number of problems Mishka can solve.
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
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][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 55.
In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than kk.
In the third example, Mishka's solving skill is so amazing that he can solve all the problems.
ac代码;
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,k,a[110],flag1,flag2,cnt=0;
cin>>n>>k;
flag1=1,flag2=n;
for(int i=1;i<=n;i++) cin>>a[i];
while(flag1<=flag2)
{
while(a[flag1]<=k && flag1<=flag2)
{
cnt++;
flag1++;
}
while(a[flag2]<=k && flag1<=flag2)
{
cnt++;
flag2--;
}
if(a[flag1]>k&&a[flag2]>k) break;
}
cout<<cnt<<endl;
return 0;
}
CodeForces999A-Mishka and Contest的更多相关文章
- Mishka and Contest(模拟水题)
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...
- CF A.Mishka and Contest【双指针/模拟】
[链接]:CF/4892 [题意]: 一个人解决n个问题,这个问题的值比k小, 每次只能解决最左边的或者最右边的问题 解决了就消失了.问这个人能解决多少个问题. [代码]: #include<b ...
- CF999A Mishka and Contest 题解
Content 能力值为 \(k\) 的小 M 参加一次考试,考试一共有 \(n\) 道题目,每道题目的难度为 \(a_i\).小 M 会选择两头中的一道难度不超过他的能力值题目去做,每做完一道,这道 ...
- ACM 第二天
A - Mishka and Contest Mishka started participating in a programming contest. There are n problems i ...
- [Codeforces]Codeforces Round #490 (Div. 3)
Mishka and Contest #pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JU ...
- Codeforces Round #365 (Div. 2) D. Mishka and Interesting sum 离线+线段树
题目链接: http://codeforces.com/contest/703/problem/D D. Mishka and Interesting sum time limit per test ...
- Codeforces 703B. Mishka and trip 模拟
B. Mishka and trip time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- CodeForces-999A-Mishka and Contest
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
随机推荐
- js数组方法大全(上)
# js数组方法大全(上) 记录一下整理的js数组方法,免得每次要找方法都找不到.图片有点多,注意流量,嘻嘻! 本期分享 join() reverse() sort() concat() slice( ...
- Centos 6/7 常用命令总结 (基础)
Centos 6/7 常用命令总结 (基础): 参考链接:https://www.cnblogs.com/linhaifeng/p/6045600.html 目录介绍: a) bin目录:用来存放常用 ...
- nyoj 20-吝啬的国度 (DFS)
20-吝啬的国度 内存限制:64MB 时间限制:1000ms Special Judge: No accepted:12 submit:43 题目描述: 在一个吝啬的国度里有N个城市,这N个城市间只有 ...
- nyoj 463-九九乘法表
463-九九乘法表 内存限制:64MB 时间限制:1000ms 特判: No 通过数:16 提交数:41 难度:1 题目描述: 小时候学过的九九乘法表也许将会扎根于我们一生的记忆,现在让我们重温那些温 ...
- Serlvet之cookie和session学习
HTTP 协议 Web通信需要一种语言,就像中国人讲中文,欧美说英文,Web使用的HTTP协议,也叫超文本协议. 使用HTTP协议的人分为两类:客户端和服务端.请求资源的角色是客户端,提供资源的是服务 ...
- Ubuntu 16.04源码编译boost库 编写CMakeLists.txt | compile boost 1.66.0 from source on ubuntu 16.04
本文首发于个人博客https://kezunlin.me/post/d5d4a460/,欢迎阅读! compile boost 1.66.0 from source on ubuntu 16.04 G ...
- MySQL数据库优化技巧有哪些?
开启查询缓存,优化查询. explain你的select查询,这可以帮你分析你的查询语句或是表结构的性能瓶颈.EXPLAIN的查询结果还会告诉你你的索引主键被如何利用的,你的数据表是如何被搜索和排序的 ...
- 如何通过swoole加速laravel的问题?
这篇文章主要介绍了关于如何使用swoole加速laravel,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 再来复习一下吧,导致 php 慢的各种因素中解析性语言的特性可以说是罪魁祸首 ...
- Spring基于注解的配置1——@Required、@Autowired、@Qualifier示例及与传统注入方法的对比
@Required注释 作用:用于属性的set方法,那么这个属性必须在xml文件的bean标签里面进行配置,否则就会抛出一个BeanInitializationException异常. 首先准备一个类 ...
- LVM扩容之xfs文件系统
LVM的基础请见:https://www.cnblogs.com/wxxjianchi/p/9698089.html 一.放大LV的容量.放大容量是由内而外来操作的. 1.设置新的lvm分区:用fdi ...