999A - Mishka and Contest

A. Mishka and Contest
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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?

Input

The first line of input contains two integers nn and kk (1n,k1001≤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 (1ai1001≤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.

Output

Print one integer — the maximum number of problems Mishka can solve.

Examples
input
Copy
8 4
4 2 3 1 5 1 6 4
output
Copy
5
input
Copy
5 2
3 1 2 1 3
output
Copy
0
input
Copy
5 100
12 34 55 43 21
output
Copy
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][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.


题意:一个人解决n个问题,这个问题的值比k小,每次只能解决最左边的或者最右边的问题,解决了就消失了。问这个人能解决多少个问题。

题解:模拟  可以先从左向右开始找小于等k的,然后删除掉,否则跳出循环,然后从右边向左找小于等于k的,删掉,大于k跳出循环。还可以不用删除,直接找小于的。

#include<bits/stdc++.h>
using namespace std;
int n,k,a[110],b[110],ans;
int main()
{
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>a[i];
    for(int i=0; i<n; i++)
        if(a[i]<=k)
            ans++,b[i]=1;
            else break;
    for(int i=n-1; i>=0; i--)
        if(a[i]<=k&&!b[i])
            ans++;
            else break;
    cout<<ans;
    return 0;
}
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
while a and a[0]<=k:
    a.pop(0);ans+=1
a.reverse()
while a and a[0]<=k:
    a.pop(0);ans+=1
print (ans)



猜你喜欢

转载自blog.csdn.net/memory_qianxiao/article/details/80774551
999