CodeForces-999A-Mishka and Contest
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;
}
CodeForces-999A-Mishka and Contest的更多相关文章
- codeforces 703E Mishka and Divisors
		
codeforces 703E Mishka and Divisors 题面 给出大小为\(1000\)的数组和一个数\(k\),求长度最短的一个子序列使得子序列的元素之积是\(k\)的倍数,如果有多 ...
 - Codeforces 703D Mishka and Interesting sum 离线+树状数组
		
链接 Codeforces 703D Mishka and Interesting sum 题意 求区间内数字出现次数为偶数的数的异或和 思路 区间内直接异或的话得到的是出现次数为奇数的异或和,要得到 ...
 - 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 703D Mishka and Interesting sum(树状数组+扫描线)
		
[题目链接] http://codeforces.com/contest/703/problem/D [题目大意] 给出一个数列以及m个询问,每个询问要求求出[L,R]区间内出现次数为偶数的数的异或和 ...
 - CodeForces 377B---Preparing for the Contest(二分+贪心)
		
C - Preparing for the Contest Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d ...
 - Mishka and Contest(模拟水题)
		
Mishka started participating in a programming contest. There are nn problems in the contest. Mishka' ...
 - CodeForces B. Creating the Contest
		
http://codeforces.com/contest/1029/problem/B You are given a problemset consisting of nn problems. T ...
 - codeforces   B. Valera and Contest   解题报告
		
题目链接:http://codeforces.com/problemset/problem/369/B 题目意思:给出6个整数, n, k, l, r, sall, sk ,需要找出一个满足下列条件的 ...
 - CodeForces 703A Mishka and Game
		
简单题. #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #inclu ...
 - Codeforces 140D - New Year Contest
		
140D - New Year Contest 思路:贪心+排序.罚时与时间成正比,因为在0点前做完的题都可以在0点提交.从时间短的开始做最优. 代码: #include<bits/stdc++ ...
 
随机推荐
- 控制层传递参数到jsp页面,jsp页面进行接收
			
在java代码中,控制层方法如下(采用model,还有其他方式) public String mysave(MyTreeMould myTreeMould, Model model) {...... ...
 - mysql  导出 导入
			
一.导出 windows下 切换到mysql安装目录bin目录下 导出 数据库lz_garden 下的 所有表结构 到d盘并命名为lz_garden.sql: D:\dev\MySQL\MySQL S ...
 - 反汇编分析NSString,你印象中的NSString是这样吗
			
我们先来定义三个NSString -(void) testNSString { NSString* a = @"abc"; NSString* b = [NSString stri ...
 - ReadWriteLock: 读写锁
			
ReadWriteLock: 读写锁 ReadWriteLock: JDK1.5提供的读写分离锁,采用读写锁分离可以有效帮助减少锁竞争. 特点: 1).使用读写锁.当线程只进行读操作时,可以允许多个线 ...
 - Git的使用和基本概念理解
			
参考:https://www.liaoxuefeng.com/wiki/896043488029600 一).git的使用: 1.创建版本库(Resopsitory),相当于一个目录,目录中所有的文件 ...
 - React源码 React.Children
			
children是什么意思呢?就是我们拿到组件内部的props的时候,有props.children这么一个属性,大部分情况下,我们直接把 props.children 渲染到 JSX 里面就可以了. ...
 - EntityFramework Core 3.0查询
			
前言 随着.NET Core 3.0的发布,EF Core 3.0也随之正式发布,关于这一块最近一段时间也没太多去关注,陆续会去对比之前版本有什么变化没有,本节我们来看下两个查询. 分组 我们知道在E ...
 - 前端WEB编辑器最爱——webstrom
			
欲先善其事,必先利其器,如题.看到网上一篇介绍webstrom的文章,觉得功能确实强大,也知道为什么阿里巴巴的前端传到github上的文件为啥都有一个 .idea 文件,(传说淘宝内部推荐写js用we ...
 - 使用spring boot配置Gmail邮箱发送邮件
			
最近项目有用到配置Gmail来发送通知邮件给客户,由于国内众所周知的原因,联调测试中遇到了一些问题,不过好在都一一解决了,现在做个记录,也给其他同仁做个参考. 相关配置: spring.mail.ho ...
 - CentOS 7 安装 dnsmasq 服务 实现内网DNS
			
目录 安装 配置 服务管理 测试解析 安装 废话不多述,上来就安装 yum install -y bind-utils dnsmasq 配置 [root@jenkins ~]# rpm -ql dns ...