{"problem":{"name":"A. Mishka and Contest","description":{"content":"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","description_type":"Markdown"},"platform":"Codeforces","limit":{"time_limit":1000,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"CF999A"},"statements":[{"statement_type":"Markdown","content":"Mishka started participating in a programming contest. There are $n$ problems in the contest. Mishka's problem-solving skill is equal to $k$.\n\nMishka 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.\n\nMishka 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.\n\nHow many problems can Mishka solve?\n\n## Input\n\nThe 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.\n\nThe 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.\n\n## Output\n\nPrint one integer — the maximum number of problems Mishka can solve.\n\n[samples]\n\n## Note\n\nIn 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$.\n\nIn the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than $k$.\n\nIn the third example, Mishka's solving skill is so amazing that he can solve all the problems.","is_translate":false,"language":"English"},{"statement_type":"Markdown","content":"Mishka 开始参加一场编程竞赛。竞赛中有 $n$ 道题目。Mishka 的解题能力为 $k$。\n\nMishka 将竞赛中的所有题目排成一个列表。由于他奇怪的原则，Mishka 只能从列表的某一端解题。每次他都会选择从左端还是右端解下一题。因此，Mishka 解决的每道题都是列表中最左或最右的题目。\n\nMishka 无法解决难度大于 $k$ 的题目。当他解决一道题时，该题会从列表中移除，因此列表长度减少 $1$。当 Mishka 无法从任一端解决任何题目时，他停止解题。\n\nMishka 最多能解决多少道题？\n\n输入的第一行包含两个整数 $n$ 和 $k$（$1 lt.eq n, k lt.eq 100$）——竞赛中的题目数量和 Mishka 的解题能力。\n\n第二行包含 $n$ 个整数 $a_1, a_2, dots.h, a_n$（$1 lt.eq a_i lt.eq 100$），其中 $a_i$ 是第 $i$ 道题的难度。题目按从左到右的顺序给出。\n\n请输出一个整数——Mishka 最多能解决的题目数量。\n\n在第一个例子中，Mishka 可以按以下顺序解题：$[ 4, 2, 3, 1, 5, 1, 6, 4 ] arrow.r [ 2, 3, 1, 5, 1, 6, 4 ] arrow.r [ 2, 3, 1, 5, 1, 6 ] arrow.r [ 3, 1, 5, 1, 6 ] arrow.r [ 1, 5, 1, 6 ] arrow.r [ 5, 1, 6 ]$，因此他解决的题目数量为 $5$。\n\n在第二个例子中，Mishka 无法解决任何题目，因为两端的题目难度都大于 $k$。\n\n在第三个例子中，Mishka 的解题能力如此惊人，以至于他能解决所有题目。\n\n## Input\n\n输入的第一行包含两个整数 $n$ 和 $k$（$1 lt.eq n, k lt.eq 100$）——竞赛中的题目数量和 Mishka 的解题能力。第二行包含 $n$ 个整数 $a_1, a_2, dots.h, a_n$（$1 lt.eq a_i lt.eq 100$），其中 $a_i$ 是第 $i$ 道题的难度。题目按从左到右的顺序给出。\n\n## Output\n\n请输出一个整数——Mishka 最多能解决的题目数量。\n\n[samples]\n\n## Note\n\n在第一个例子中，Mishka 可以按以下顺序解题：$[ 4, 2, 3, 1, 5, 1, 6, 4 ] arrow.r [ 2, 3, 1, 5, 1, 6, 4 ] arrow.r [ 2, 3, 1, 5, 1, 6 ] arrow.r [ 3, 1, 5, 1, 6 ] arrow.r [ 1, 5, 1, 6 ] arrow.r [ 5, 1, 6 ]$，因此他解决的题目数量为 $5$。在第二个例子中，Mishka 无法解决任何题目，因为两端的题目难度都大于 $k$。在第三个例子中，Mishka 的解题能力如此惊人，以至于他能解决所有题目。","is_translate":true,"language":"Chinese"},{"statement_type":"Markdown","content":"Let $ n, k \\in \\mathbb{N} $, with $ 1 \\leq n, k \\leq 100 $.  \nLet $ \\mathbf{a} = (a_1, a_2, \\dots, a_n) $ be a sequence of integers with $ 1 \\leq a_i \\leq 100 $ for all $ i \\in \\{1, 2, \\dots, n\\} $.\n\nDefine a process where, at each step, Mishka may remove either the leftmost or the rightmost element of the current sequence **if and only if** its value is $ \\leq k $.  \nThe process terminates when neither the leftmost nor the rightmost element is $ \\leq k $.\n\nLet $ S \\subseteq \\{1, 2, \\dots, n\\} $ be the set of indices of problems solved.  \nThe goal is to maximize $ |S| $.\n\nFormally, define a sequence of subarrays $ \\mathbf{a}^{(0)}, \\mathbf{a}^{(1)}, \\dots, \\mathbf{a}^{(m)} $, where:\n- $ \\mathbf{a}^{(0)} = \\mathbf{a} $,\n- $ \\mathbf{a}^{(t+1)} $ is obtained from $ \\mathbf{a}^{(t)} $ by removing either its first or last element $ x $, provided $ x \\leq k $,\n- The process stops at the smallest $ m $ such that both the first and last elements of $ \\mathbf{a}^{(m)} $ are $ > k $, or the sequence is empty.\n\n**Objective:** Find the maximum possible value of $ m $.\n\nThis is equivalent to:  \nFind the maximum number of elements that can be removed from the ends of $ \\mathbf{a} $, one at a time, such that each removed element is $ \\leq k $, and removal stops when neither end is removable.\n\nLet $ l = 0 $, $ r = n - 1 $.  \nWhile $ l \\leq r $ and $ (a_l \\leq k \\text{ or } a_r \\leq k) $:  \n  If $ a_l \\leq k $ and $ a_r \\leq k $:  \n    Choose either (greedily, both lead to same max count in optimal strategy), increment counter, and move pointer.  \n  Else if $ a_l \\leq k $: remove left, increment $ l $, increment counter.  \n  Else if $ a_r \\leq k $: remove right, decrement $ r $, increment counter.  \n  Else: break.\n\n**Answer:** The total number of elements removed.\n\n**Formal Output:**  \nLet $ \\text{count} = 0 $, $ l = 0 $, $ r = n - 1 $.  \nWhile $ l \\leq r $:  \n  If $ a_l \\leq k $ and $ a_r \\leq k $:  \n    $ \\text{count} \\gets \\text{count} + 1 $, and set $ l \\gets l + 1 $ (or $ r \\gets r - 1 $; either yields same max).  \n  Else if $ a_l \\leq k $:  \n    $ \\text{count} \\gets \\text{count} + 1 $, $ l \\gets l + 1 $.  \n  Else if $ a_r \\leq k $:  \n    $ \\text{count} \\gets \\text{count} + 1 $, $ r \\gets r - 1 $.  \n  Else: break.  \n\nReturn $ \\text{count} $.","is_translate":false,"language":"Formal"}],"meta":{"iden":"CF999A","tags":["brute force","implementation"],"sample_group":[["8 4\n4 2 3 1 5 1 6 4","5"],["5 2\n3 1 2 1 3","0"],["5 100\n12 34 55 43 21","5"]],"created_at":"2026-03-03 11:00:39"}}