【CF 1029B】Creating the Contest

                                 B. Creating the Contest

You are given a problemset consisting of nn problems. The difficulty of the ii-th problem is aiai. It is guaranteed that all difficulties are distinct and are given in the increasing order.

You have to assemble the contest which consists of some problems of the given problemset. In other words, the contest you have to assemble should be a subset of problems (not necessary consecutive) of the given problemset. There is only one condition that should be satisfied: for each problem but the hardest one (the problem with the maximum difficulty) there should be a problem with the difficulty greater than the difficulty of this problem but not greater than twice the difficulty of this problem. In other words, let ai1,ai2,…,aipai1,ai2,…,aip be the difficulties of the selected problems in increasing order. Then for each jj from 11 to p−1p−1 aij+1≤aij⋅2aij+1≤aij⋅2 should hold. It means that the contest consisting of only one problem is always valid.

Among all contests satisfying the condition above you have to assemble one with the maximum number of problems. Your task is to find this number of problems.

Input

The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of problems in the problemset.

The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — difficulties of the problems. It is guaranteed that difficulties of the problems are distinct and are given in the increasing order.

Output

Print a single integer — maximum number of problems in the contest satisfying the condition in the problem statement.

Examples

input

10
1 2 5 6 7 10 21 23 24 49

output

4

input

5
2 10 50 110 250

output

1

input

6
4 7 12 100 150 199

output

3

 

题意:给出有n个元素的数组,数组中的元素已按升序排好。你需要找出这样一个最大序列:序列中的每个相邻元素的差值不能大于较小元素的二倍,即 an-1 * 2>=an. 

水题,运用尺取法的原理寻找最长序列。

代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define closeio std::ios::sync_with_stdio(false)

int a[200005];

int main()
{
	int n,i,j,l,r,maxn=0;
	cin>>n;
	cin>>a[0];
	l=a[0];
	j=0;
	for(i=1;i<n;i++)
	{
		cin>>a[i];
		if(l*2>=a[i])
		{
			maxn=max(maxn,i-j);
			//cout<<maxn+1<<" "<<l<<" "<<a[i]<<endl;	
		}	
		else
		 	j=i;
		l=a[i];
		/*for(int k=j;k<=i;k++)
			cout<<a[k]<<" ";
		cout<<endl;*/
	}	
	cout<<maxn+1<<endl;
	return 0;
}

 

全部评论

相关推荐

03-28 19:11
铜陵学院 C++
有礼貌的山羊追赶太阳:太典了,连笔试都没有开始就因为HC满了而结束了,而且还卡你不让你再投其他部门的。
点赞 评论 收藏
分享
昨天 12:23
已编辑
华南理工大学 Java
野猪不是猪🐗:给他装的,双九+有实习的能看的上这种厂我直接吃⑨✌们拿它练练面试愣是给他整出幻觉了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务