1029 B. Creating the Contest C++

25 篇文章 0 订阅

题目地址:http://codeforces.com/problemset/problem/1029/B

题目:

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

Copy

10
1 2 5 6 7 10 21 23 24 49

output

Copy

4

input

Copy

5
2 10 50 110 250

output

Copy

1

input

Copy

6
4 7 12 100 150 199

output

Copy

3

Note

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

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

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

 思路:

一开始看错题目了,然后n^2一直超时。于是重新看了一下题,题意是这样子的,有一串数字,要求a(i)<a(i+1)<=2a(i),比如第一个样例1,2可以,5,6可以,6,7可以……但是2,5不可以,所以5,6和6,7可以连起来,这样下去,最多可以连5 6 7 10,也就是四个数字,于是输出4.到这里我们就发现了,这就是一个最长连续子序列的变形,用的是dp。

代码:

#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
using namespace std;
long long int a[999999];
long long int b[999999];
long long int dp[999999];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        memset(dp,0,sizeof(dp));
        for(long long int i=0;i<n;i++)
        {
            scanf("%lld",&a[i]);
            b[i]=a[i]*2;
            dp[i]=1;
        }
        long long int sum=1;

        for(long long int i=1;i<n;i++)
        {
            if(a[i]<=b[i-1])dp[i]=max(dp[i],dp[i-1]+1);
            sum=max(sum,dp[i]);
        }
        cout<<sum<<endl;
    }
    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值