A - Kefa and First Steps
Problem description
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.
解题思路:求最大非递减序列的长度,注意maxlen初始值为1,水过!
AC代码:
#include<bits/stdc++.h>
using namespace std;
int n,len=,maxlen=,a[];
int main(){
cin>>n;
for(int i=;i<n;++i)cin>>a[i];
for(int i=;i<n;++i){
if(a[i]>=a[i-])len++;
else len=;
maxlen=max(maxlen,len);
}
cout<<maxlen<<endl;
return ;
}
A - Kefa and First Steps的更多相关文章
- 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 ...
- Codeforces 580A - Kefa and First Steps
580A - Kefa and First Steps 思路:dp dp[i]表示包括前i个元素中a[i]在内的最大增序列. 代码: #include<bits/stdc++.h> usi ...
- 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 ...
- Codeforces Round #321 (Div. 2)-A. Kefa and First Steps,暴力水过~~
A. Kefa and First Steps time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- 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 ...
- Codeforces Round #321 (Div. 2) Kefa and First Steps 模拟
原题连接:http://codeforces.com/contest/580/problem/A 题意: 给你一个序列,问你最长不降子串是多长? 题解: 直接模拟就好了 代码: #include< ...
- Codeforces Round #321 (Div. 2) A, B, C, D, E
580A. Kefa and First Steps 题目链接: A. Kefa and First Steps 题意描述: 给出一个序列,求最长不降连续子序列多长? 解题思路: 水题,签到 代码: ...
- Codeforces Round #321 (Div. 2)
水 A - Kefa and First Steps /************************************************ * Author :Running_Time ...
- animation-timing-function: steps() 详解
在应用 CSS3 渐变/动画时,有个控制时间的属性 <animation-timing-function> .它的取值中除了常用到的 贝萨尔曲线以外,还有个让人比较困惑的 steps() ...
随机推荐
- NLP:单词嵌入Word Embeddings
深度学习.自然语言处理和表征方法 原文链接:http://blog.jobbole.com/77709/ 一个感知器网络(perceptron network).感知器 (perceptron)是非常 ...
- Graph network classification(As a beginner, continue to update)
Data arrangement 1.Reference Webs http://nlp.csai.tsinghua.edu.cn/~tcc/ https://blog.csdn.net/a60964 ...
- anaconda安装的TensorFlow版本没有model这个模块
一.采用git bash来安装,确认已经安装了git 二.手动找到TensorFlow的模块文件夹地址,若不知道,输入以下两行代码: import tensorflow as tf tf.__path ...
- Linux思维导图之进程管理
查漏补缺,理解概念,及时总结,欢迎拍砖.
- ecshop ad调用指定广告的方法 邓士鹏
在include/lib_goods.php文件下面新增:function getads($cat,$num){$time = gmtime();$sql = "SELECT * FRO ...
- Eureka 服务的注册和发现
二.Eureka 服务端 1.新建一个 maven module 子项目 microservicecloud-eureka-server 2.pom.xml <project xmlns=&qu ...
- ZOJ 2699 Police Cities
Police Cities Time Limit: 10 Seconds Memory Limit: 32768 KB Once upon the time there lived a ki ...
- [bzoj1452][JSOI2009]Count_树状数组
Count bzoj-1452 JSOI-2009 题目大意:请维护一个平面内的数据结构,支持:单点修改,查询矩形内给定权值出现次数. 注释:$1\le n,m\le 300$,$1\le Q \le ...
- MYSQL 源码解读系列 [线程池。。] ----dennis的博客
http://blog.sina.com.cn/s/articlelist_1182000643_0_1.html
- 配置db账号和密码时一定注意空格问题、空行问题否则连接报错
#postgresql dbpg.datasource.type=com.alibaba.druid.pool.DruidDataSourcepg.datasource.driverClassName ...