Codeforces Round #490 (Div. 3) A. 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?

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.


从前往后遍历,从后往前遍历即可。

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define maxn 2000005
#define inf 0x3f3f3f3f
#define ii 0x3f
const int mod = 1e9 + 7;


ll read() {
	ll x = 0, f = 1;
	char ch = getchar();
	while (ch < '0'||ch > '9') {
		if (ch == '-') {
			f = -1;
			
		}
		ch = getchar();
	}
	while (ch >= '0'&&ch <= '9') {
		x = x * 10 + ch - '0';
		ch = getchar();
	}
	return x * f;
}

ll quickpow(ll a,ll b) {
	ll ans = 1;
	while (b > 0) {
		if (b % 2)ans = ans * a;
		b = b / 2;
		a = a * a;
	}
	return ans;
}

int a[maxn];
int cn[105];
int main() {
	//ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	int i, j;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		//cn[a[i]] = 1;
	}
	int flag = n-1;
	int cnt = 0;
	for (i = 0; i < n; i++) {
		if (a[i] <= k)cnt++;
		else {
			flag = i;
			break;
		}

	}
	//cout << flag << endl;
	for (i = n - 1; i >= flag+1; i--) {
		if (a[i] <= k)cnt++;
		else break;
	}
	cout << cnt << endl;
}



猜你喜欢

转载自blog.csdn.net/qq_40273481/article/details/80774431