A11771 | Mishka and Contest
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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?
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?
输入格式
The first line of input contains two integers $n$ and $k$ ( $1 \le n, k \le 100$ ) — the number of problems in the contest and Mishka's problem-solving skill.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 100$ ), where $a_i$ is the difficulty of the $i$ -th problem. The problems are given in order from the leftmost to the rightmost in the list.
The second line of input contains $n$ integers $a_1, a_2, \dots, a_n$ ( $1 \le a_i \le 100$ ), where $a_i$ is the difficulty of the $i$ -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.
输入输出样例
输入 #1
8 4 4 2 3 1 5 1 6 4
输出 #1
5
输入 #2
5 2 3 1 2 1 3
输出 #2
0
输入 #3
5 100 12 34 55 43 21
输出 #3
5
In the first example, Mishka can solve problems in the following order: $[4, 2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6, 4] \rightarrow [2, 3, 1, 5, 1, 6] \rightarrow [3, 1, 5, 1, 6] \rightarrow [1, 5, 1, 6] \rightarrow [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.
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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted