Codeforces Round #506 (Div. 3)B.Creating the Contest(dp)

Posted knmxx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #506 (Div. 3)B.Creating the Contest(dp)相关的知识,希望对你有一定的参考价值。

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 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+1aij?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 (1n2?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 (1ai1091≤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].

我怕不是智障数组开小了无限TLE。。。

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int n;
 8     int a[200010];
 9     int dp[200010];
10     int result = 0;
11     scanf("%d",&n);
12     dp[0] = 0;
13 
14     for(int i = 1;i<=n;++i)
15     {
16         scanf("%d",&a[i]);
17         dp[i] = 1;
18         if(a[i-1]*2>=a[i])
19                // break;
20                {
21                    if(dp[i]<dp[i-1]+1)
22                     dp[i] = dp[i-1]+1;
23 
24                }
25             if(result<dp[i])
26         result = dp[i];
27     }
28     //for(int i = 2;i<=n;++i)
29     //{
30        // for(int j = i-1;j>=1;--j)
31         //{
32             //if(a[i-1]*2>=a[i])
33                // break;
34            // dp[i] = dp[i-1]+1;
35         //}
36         //result = max(result,dp[i]);
37     //}
38     cout << result<<endl;
39     //cout << *max_element(dp+1,dp+n)<<endl;
40     return 0;
41 }

 




以上是关于Codeforces Round #506 (Div. 3)B.Creating the Contest(dp)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Round #506 (Div. 3)

Codeforces Round #506 (Div. 3) C. Maximal Intersection

Codeforces Round #506 (Div. 3) C. Maximal Intersection (枚举)

Codeforces Round #506 (Div. 3) D. Concatenated Multiples

Codeforces Round #506 (Div. 3) D-F

Codeforces Round #506 D. Concatenated Multiples题解