Codeforces #506 B. Creating the Contest

B. Creating the Contest

time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

You are given a problemset consisting of n problems. The difficulty of the i-th problem is ai. 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,,aip be the difficulties of the selected problems in increasing order. Then for each j from 1 to p−1 aij+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 n (1≤n≤2⋅10^5) — the number of problems in the problemset.

The second line of the input contains n integers a1,a2,,an (1≤ai≤10^9) — 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

Note

Description of the first example: there are 10 valid contests consisting of 1 problem, 10 valid contests consisting of 2 problems ([1,2],[5,6],[5,7],[5,10],[6,7],[6,10],[7,10],[21,23],[21,24],[23,24]), 5 valid contests consisting of 3 problems ([5,6,7],[5,6,10],[5,7,10],[6,7,10],[21,23,24]) and a single valid contest consisting of 4 problems ([5,6,7,10]).

In the second example all the valid contests consist of 1 problem.

In the third example are two contests consisting of 3 problems: [4,7,12] and [100,150,199]

概述

    给定单调上升序列,找出满足要求的最长子序列。

思路

    作为div 3的第二道题,依然水。

   看完题目第一时间想到了套O(NlogN)的LIS,但这道题比LIS还简单——为达到最大长度,每个元素只与上一个元素有关系。

代码

#include<bits\stdc++.h> 
using namespace std; 

int main(){
	int n;
	bool t=0;
	int m,cnt,a[2];
	m=cnt=0;
	cin>>n;
	while(n--){
		cin>>a[t];
		if(a[t]<=a[!t]*2)
			cnt++;
		else{
			if(cnt>m) m=cnt;
			cnt=1;
		}
		t=!t;
	}
	if(cnt>m) m=cnt;
	cout<<m;
	return 0;
}

http://www.cnblogs.com/hizcard/  转载请注明出处 

猜你喜欢

转载自blog.csdn.net/hizcard/article/details/82082648
今日推荐