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+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].

已知序列是单调递增的,找最长序列满足 前一项*2>=后一项,用单调栈(单调定义为:前一项*2>=后一项)实现即可。

#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>
#define maxn 110
#define maxm 10010
#define inf 0x3f3f3f
using namespace std;
stack<int>s;
int main()
{
while(!s.empty())
s.pop();
int n;
scanf("%d",&n);
int mm=;
int sum=;
for(int i=;i<=n;i++)
{
int x;
scanf("%d",&x);
if(s.empty())
{
sum=;
s.push(x);
}
else
{
while(!s.empty ())
{
int y=s.top();
if(y*>=x)//符合条件就放进去
{
s.push(x);
sum++;
break;
}
else//否则把前一项踢了
{
s.pop();
sum--;
}
}
if(s.empty ())
{
sum=;
s.push(x);
}
}
if(sum>mm)
mm=sum;
}
printf("%d\n",mm);
return ;
}

codeforce1029B B. Creating the Contest(简单dp,简单版单调栈)的更多相关文章

  1. 【dp 状态压缩 单调栈】bzoj3591: 最长上升子序列

    奇妙的单调栈状压dp Description 给出1~n的一个排列的一个最长上升子序列,求原排列可能的种类数. Input 第一行一个整数n. 第二行一个整数k,表示最长上升子序列的长度. 第三行k个 ...

  2. 「10.11」chess(DP,组合数学)·array(单调栈)·ants(莫队,并茶几)

    菜鸡wwb因为想不出口胡题所以来写题解了 A. chess 昨天晚上考试,有点困 开考先花五分钟扫了一边题,好开始肝$T1$ 看了一眼$m$的范围很大,第一反应矩阵快速幂?? $n$很小,那么可以打$ ...

  3. BZOJ.3238.[AHOI2013]差异(后缀自动机 树形DP/后缀数组 单调栈)

    题目链接 \(Description\) \(Solution\) len(Ti)+len(Tj)可以直接算出来,每个小于n的长度会被计算n-1次. \[\sum_{i=1}^n\sum_{j=i+1 ...

  4. Codeforces - 1033C - Permutation Game - 简单dp - 简单数论

    https://codeforces.com/problemset/problem/1033/C 一开始觉得自己的答案会TLE,但是吸取徐州赛区的经验去莽了一发. 其实因为下面这个公式是 $O(nlo ...

  5. hdu 2084 数塔(简单dp)

    题目 简单dp //简单的dp #include<stdio.h> #include<string.h> #include<algorithm> using nam ...

  6. The Preliminary Contest for ICPC China Nanchang National Invitational I. Max answer (单调栈+线段树)

    题目链接:https://nanti.jisuanke.com/t/38228 题目大意:一个区间的值等于该区间的和乘以区间的最小值.给出一个含有n个数的序列(序列的值有正有负),找到该序列的区间最大 ...

  7. E. The Contest ( 简单DP || 思维 + 贪心)

    传送门 题意: 有 n 个数 (1 ~ n) 分给了三个人 a, b, c: 其中 a 有 k1 个, b 有 k2 个, c 有 k3 个. 现在问最少需要多少操作,使得 a 中所有数 是 1 ~ ...

  8. codeforces Gym 100500H A. Potion of Immortality 简单DP

    Problem H. ICPC QuestTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/a ...

  9. Codeforces Round #302 (Div. 2) C. Writing Code 简单dp

    C. Writing Code Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/544/prob ...

随机推荐

  1. Mongodb 命令及 PyMongo 库的使用

    1. PyMongo import pymongo 1. 初始化 Mongo 客户端 client=pymongo.MongoClient(mongodb://10.85.39.45:8188,10. ...

  2. 安装基础版的kinetic

    没有gui工具 sudo apt-get install ros-kinetic-ros-base

  3. SpringMVC中的参数绑定总结

    众所周知,springmvc是用来处理页面的一些请求,然后将数据再通过视图返回给用户的,前面的几篇博文中使用的都是静态数据,为了能快速入门springmvc,在这一篇博文中,我将总结一下springm ...

  4. 为什么ubuntu窗口语言选择中文后,中文字体反而变丑了?

    首先出现这个问题是因为ubuntu在更新语言包后,会安装ukai和uming两个字体,不知道为啥ubuntu要这样设计,反正挺烦人的,又丑又不清楚,把这两个卸掉就行了 sudo apt-get rem ...

  5. HIVE之常用字符串函数

    可以参考: 博文 : https://www.iteblog.com/archives/1639.html

  6. System.ComponentModel.DataAnnotations 命名空间和RequiredAttribute 类

    System.ComponentModel.DataAnnotations 命名空间提供定义 ASP.NET MVC 和 ASP.NET 数据控件的类的特性. RequiredAttribute 指定 ...

  7. vue2 过渡动画

    <body> <div id="app"> <transition name="move"> // transition里面 ...

  8. 12.21 Gson的常用用法 功能介绍 特点

    使用谷歌GSON常用语法: 功能:映射Java Object与json格式的数据 1.通过Annotation注解来声明 2.支持自定义属性名称 3.支持包含或排除属性 4.支持自定义接口自己完成解析 ...

  9. 正则,String中用法,Pattern Matcher

    package com.正则表达式; import java.util.Scanner; /** * * 校验qq号码 * 1:要求必须是5-15位数字 * 2: 0不能开头 * 分析: * A:键盘 ...

  10. JSP session过期时间(小记)

    以下情况,Session结束生命周期,Servlet容器将Session所占资源释放:1.客户端关闭浏览器2.Session过期3.服务器端调用了HttpSession的invalidate()方法. ...