A. Kefa and First Steps
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th
day (1 ≤ i ≤ n) he makes ai money.
Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence ai.
Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order.

Help Kefa cope with this task!

Input

The first line contains integer n (1 ≤ n ≤ 105).

The second line contains n integers a1,  a2,  ...,  an (1 ≤ ai ≤ 109).

Output

Print a single integer — the length of the maximum non-decreasing subsegment of sequence a.

Examples
input
6
2 2 1 3 4 1
output
3
input
3
2 2 9
output
3
Note

In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one.

In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one.

这个题有点像求非单调递减子序列的长度,但仔细看看题发现是求连续一段非单减子数组的长度,这样和求单调递增子序列的方法很像,但看到数据范围两层循环遍历肯定会超时,题目要求的是子区间非单减的长度,为何要遍历呢?只需判断当前输入的值是否大于等于前一个的值,如果是,则此时的长度就等于前一个长度加一,反之,则此时长度为一,然后继续。看代码:

#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=100000+10;
int a[N],b[N];
int main()
{
int n,i,j;
while(~scanf("%d",&n))
{
memset(b,0,sizeof(a));
int maxx=0;
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=1;
for(j=i;j>=1;j--)
{
if(a[j]>=a[j-1]&&j!=1)
b[i]=b[j-1]+1;//用到了点动归思想;
break;//这样就不会超时了,甚至可以简化之;
}
maxx=max(maxx,b[i]);
}
printf("%d\n",maxx);
}
return 0;
}

Codeforces Round #321 (Div. 2)-A. Kefa and First Steps,暴力水过~~的更多相关文章

  1. Codeforces Round #321 (Div. 2) A. Kefa and First Steps 水题

    A. Kefa and First Steps Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/58 ...

  2. Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】

    A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  3. codeforces水题100道 第十四题 Codeforces Round #321 (Div. 2) A. Kefa and First Steps (brute force)

    题目链接:http://www.codeforces.com/problemset/problem/580/A题意:求最长连续非降子序列的长度.C++代码: #include <iostream ...

  4. Codeforces Round #321 (Div. 2) E. Kefa and Watch 线段树hash

    E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/prob ...

  5. Codeforces Round #321 (Div. 2) C. Kefa and Park dfs

    C. Kefa and Park Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/probl ...

  6. Codeforces Round #321 (Div. 2) B. Kefa and Company 二分

    B. Kefa and Company Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/pr ...

  7. Codeforces Round #321 (Div. 2) D. Kefa and Dishes 状压dp

    题目链接: 题目 D. Kefa and Dishes time limit per test:2 seconds memory limit per test:256 megabytes 问题描述 W ...

  8. Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)

    http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...

  9. Codeforces Round #321 (Div. 2) E Kefa and Watch (线段树维护Hash)

    E. Kefa and Watch time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. subline应用之常用插件

    汉化插件:ChineseLocalzations IMESupport插件:解决软件输入法跟随问题 SublimeREPL插件:可以用于运行和调试一些需要交互的程序如python SublimeCod ...

  2. React.js 的 context

    这一节我们来介绍一个你可能永远用不上的 React.js 特性 —— context.但是了解它对于了解接下来要讲解的 React-redux 很有好处,所以大家可以简单了解一下它的概念和作用. 在过 ...

  3. P1597 语句解析

    题目背景 木有背景…… 题目描述 一串(<255)PASCAL语言,只有a,b,c 3个变量,而且只有赋值语句,赋值只能是一个一位的数字或一个变量,未赋值的变量值为0.输出a,b,c 最终的值. ...

  4. List<DTO>转 Map<String,List<DTO>> 两种写法

    List<TeamScheduleDTO> list = JSON.parseArray(response.getData().getJSONArray("list") ...

  5. [转]Android APK签名原理及方法

    准备知识:数据摘要 这个知识点很好理解,百度百科即可,其实他也是一种算法,就是对一个数据源进行一个算法之后得到一个摘要,也叫作数据指纹,不同的数据源,数据指纹肯定不一样,就和人一样. 消息摘要算法(M ...

  6. XCode调试器LLDB

    与调试器共舞 - LLDB 的华尔兹 你是否曾经苦恼于理解你的代码,而去尝试打印一个变量的值? NSLog(@"%@", whatIsInsideThisThing); 或者跳过一 ...

  7. python+selenium(环境的安装)

    前言:网上的资料层次不齐,且资料也不全,容易误导新手,所以笔者愿意把你的知识免费分享给大家,笔者用的版本为:python3 此时可能新手就会问了,为什么不用python2呢,因为道理很简单,人要往前走 ...

  8. com组件简单应用

    1.打开VS2010,新建ATL COM 项目,步骤:“文件” -->“新建” -->“项目”,选择“Visual C++” -->“ATL 项目” ,填写“名称” FirstCOM ...

  9. HDU4300 Clairewd’s message(拓展kmp)

    Problem Description Clairewd is a member of FBI. After several years concealing in BUPT, she interce ...

  10. ubuntu 18.04 start myproject

    #!/bin/bash now=$(date +%Y%m%d) cmd='/home/hu/go/src/github.com/coredns/coredns/coreserver -conf /ho ...