Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】
2 seconds
256 megabytes
standard input
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!
The first line contains integer n (1 ≤ n ≤ 105).
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109).
Print a single integer — the length of the maximum non-decreasing subsegment of sequence a.
6
2 2 1 3 4 1
3
3
2 2 9
3
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 <bits/stdc++.h> using namespace std;
const int N = 1e5+;
int n,a[N],ans,maxn;
int main()
{
cin>>n;
for(int i=;i<n;i++)//0开始
cin>>a[i];
for(int i=;i<=n;i++)//1开始
{
if(a[i]>=a[i-])
{
ans++;
maxn=max(maxn,ans);
}
else
ans=;
}
cout<<maxn+<<endl;
return ;
}
Codeforces Round #321 (Div. 2) A. Kefa and First Steps【暴力/dp/最长不递减子序列】的更多相关文章
- 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 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 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 ...
- 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) E. Kefa and Watch 线段树hash
E. Kefa and Watch Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/580/prob ...
- 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 ...
- 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 ...
- Codeforces Round #321 (Div. 2) D. Kefa and Dishes(状压dp)
http://codeforces.com/contest/580/problem/D 题意: 有个人去餐厅吃饭,现在有n个菜,但是他只需要m个菜,每个菜只吃一份,每份菜都有一个欢乐值.除此之外,还有 ...
- 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 ...
随机推荐
- 利用插件对某些网页执行javascript代码
说明 javascript在浏览器地址栏中可以运行,也可以按F12在控制台中运行,还可以写一个插件让javascript针对某些网页执行,可以使用chrome浏览器的Content scripts,C ...
- BFC相关知识
一.什么是BFC css布局主要采用盒子模型(BOX),元素的类型和 display 属性,决定了 Box 的类型,常见的盒子类型有两种: block-level box:display 属性为 bl ...
- SSTI注入绕过(沙盒逃逸原理一样)
在python沙盒逃逸中绕过道理是一样的. 1.python沙盒中删除了很多模块,但是没有删除reload reload(__builtins__),重新加载被删除的模块,直接命令执行,只用于py2 ...
- Kotlin中的“忍者”函数 —— 理解泛型的能力(KAD 12)
作者:Antonio Leiva 时间:Feb 8, 2017 原文链接:https://antonioleiva.com/generic-functions-kotlin/ Kotlin的一些特性组 ...
- 你的第一个自动化测试:Appium 自动化测试
前言: 这是让你掌握 App 自动化的文章 一.前期准备 本文版权归作者和博客园共有,原创作者:http://www.cnblogs.com/BenLam,未经作者同意必须在文章页面给出原文连接. 1 ...
- 安装启动Apache2.4后报Invalid command 'Order', perhaps misspelled or defined by a module not included in the server configuration错误
LoadModule access_compat_module modules/mod_access_compat.so 取消这一行模块的注释,再重启服务即可. 搜索 mod_access_compa ...
- IPMITool driver
官网链接: https://docs.openstack.org/ironic/latest/admin/drivers/ipmitool.html IPMITool driver 概述IPMI(In ...
- mysql安装目录、配置文件存放位置
linux系统下,如何知道mysql使用的配置文件到底是哪个呢?linux自带的mysql的安装目录又是什么呢?数据存放在什么目录下? 1.linux系统自带的mysql,其安装目录及数据目录查看方法 ...
- gulp-API介绍
使用gulp,一般只需要用4个API:gulp.src(),gulp.dest(),gulp.task(),gulp.watch(). 1. gulp.src() 用来获取流的,但是要注意的是这个流里 ...
- 洛谷 P4139 上帝与集合的正确用法 解题报告
P4139 上帝与集合的正确用法 题目描述 根据一些书上的记载,上帝的一次失败的创世经历是这样的: 第一天, 上帝创造了一个世界的基本元素,称做"元". 第二天, 上帝创造了一个新 ...