Gym - 101911K Medians and Partition 思维

Let median of some array be the number which would stand in the middle of this array if it was sorted beforehand. If the array has even length let median be smallest of of two middle elements. For example, median of the array [10,3,2,3,2][10,3,2,3,2] is 33 (i.e. [2,2,3–,3,10][2,2,3_,3,10]). Median of the array [1,5,8,1][1,5,8,1] is 11 (i.e. [1,1–,5,8][1,1_,5,8]).

Let array be mm-good if its median is greater or equal than mm.

Let the partition of array [a1,a2,…,an][a1,a2,…,an] be a set of subarrays {b1,b2,…,bk}{b1,b2,…,bk} such that b1=[a1,a2,…,ai1]b1=[a1,a2,…,ai1], b2=[ai1+1,ai1+2,…,ai2]b2=[ai1+1,ai1+2,…,ai2], ..., bk=[aik−1+1,aik−1+2,…,an]bk=[aik−1+1,aik−1+2,…,an]. For example, array [10,3,2,3,2][10,3,2,3,2] can be partitioned as follows: {[10,3,2,3,2]}{[10,3,2,3,2]} or {[10],[3],[2],[3],[2]}{[10],[3],[2],[3],[2]}, or {[10],[3,2,3,2]}{[10],[3,2,3,2]}, or {[10,3],[2],[3,2]}{[10,3],[2],[3,2]} and so on.

You are given array aa of length nn and integer mm. Find the partition of aa into maximum number of subarrays such that each subarray is mm-good.

Input

The first line contains two integers nn and mm (1≤n≤50001≤n≤5000, 1≤m≤50001≤m≤5000) — length of array aa and constant mm.

The second line contains nn integers a1a1, a2a2, ..., anan (1≤ai≤50001≤ai≤5000)— array aa.

Output

If there is no valid partition of array aa into mm-good subarrays, print 00. Otherwise print maximum number of subarrays in partition of array aa such that each subarray is mm-good.

Examples

Input

5 2
10 3 2 3 2

Output

5

Input

5 3
10 3 2 3 2

Output

1

Input

5 4
10 3 2 3 2

Output

0

题意:最多能分成多少个连续子序列都满足中位数大于等于m

题解:一个序列中位数大于等于m,当然大于等于m的数量 - 小于m的数量 >= 1 ,所以我们就让他等于1即可,就让每个序列大于等于m的数量比小于m的数量多一个,为什么一定符合呢,因为若当前序列不符合肯定要再增加两边的数,增加后若符合即可,若增加后还不符合就继续增加,但此时大于等于m的数量 是小于等于 小于m的数量。因此我们就统计一下大于等于m的数量和小于m的数量即可

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;

int n,m;

int main()
{
	while(~scanf("%d%d",&n,&m))
	{
		int x;
		int s1=0,s2=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&x);
			if(x<m) s1++;
			else s2++;
		}
		printf("%d\n",max(0,s2-s1));
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值