codeforces 580A Kefa and First Steps

A. Kefa and First Steps

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.

Sample test(s)

Input

62 2 1 3 4 1

Output

3

Input

32 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.

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int a[100005];
 8     int n;
 9     scanf("%d",&n);
10     for(int i=0;i<n;i++)
11         scanf("%d",&a[i]);
12     int ans=0,maxn=1;
13     for(int i=1;i<n;i++)
14         if(a[i]>=a[i-1])maxn++;
15         else ans=max(maxn,ans),maxn=1;
16     ans=max(maxn,ans);
17     printf("%d\n",ans);
18     return 0;
19 }
时间: 2024-10-18 05:44:01

codeforces 580A Kefa and First Steps的相关文章

[2016-03-23][codeforces][580][A][Kefa and First Steps]

时间:2016-03-23 13:04:56 星期三 题目编号:[2016-03-23][codeforces][580][A][Kefa and First Steps] 题目大意:求最长上升子串 #include <cstdio> using namespace std; int a[100000 + 100]; int main(){ int n; scanf("%d",&n); for(int i = 0 ;i < n ;++i) scanf(&quo

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> using namespace std; const int maxn = 100100; int n, a[maxn], tmp, ans; int main() { cin >> n; for (int i = 0; i < n; i ++) cin >> a[i]

dp + 状态压缩 - Codeforces 580D Kefa and Dishes

Kefa and Dishes Problem's Link Mean: 菜单上有n道菜,需要点m道.每道菜的美味值为ai. 有k个规则,每个规则:在吃完第xi道菜后接着吃yi可以多获得vi的美味值. 问:最多可以获得多少美味值? (1≤m≤n≤18,0≤k≤n∗(n−1)) analyse: 经典的状压DP. 由于最多18道菜,可用一个数s(s<=2^18)来唯一标识一种状态. 对于一个状态s,枚举两个位置i和j:i从已选择的菜中选定,j从未选择的菜中选定. 下一个状态ss的就是:吃完i后接着

CodeForces 580B Kefa and Company

Description: Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company. Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has a

codeforces 580D Kefa and Dishes

C. Kefa and Park Kefa decided to celebrate his first big salary by going to the restaurant. He lives by an unusual park. The park is a rooted tree consisting of n vertices with the root at vertex 1. Vertex 1 also contains Kefa's house. Unfortunaely f

Codeforces 580D Kefa and Dishes(状态压缩DP)

题目链接:http://codeforces.com/problemset/problem/580/D 题目大意:有n盘菜每个菜都有一个满意度,k个规则,每个规则由x y c组成,表示如果再y之前吃x那么满意度会额外增加c,现在凯迪想吃m盘菜,并且满意度最大,请求出满意度.解题思路:状压DP,设dp[i][j]表示在状态i并且最后一道菜放在位置j时的最大满意度.注意要处理好一道菜时的情况,以及注意二进制表示中1的个数超过m的情况. 代码: 1 #include<bits/stdc++.h> 2

【线段树+HASH】CODEFORCES 580E Kefa and Watch

通道 题意:0-9字符串,区间修改,区间询问是否d周期 思路:直接暴力线段树,然后HASH修改和查询,卡HASH的话就双HASH. 代码: #include<cstdio> #include<cstring> typedef long long ll; const int N = 100007; int n, m, k, lens; char s[N]; #define lch id<<1 #define rch id<<1|1 class HashTree

Codeforces 580D Kefa and Dishes(状压DP)

题目大概说要吃掉n个食物里m个,吃掉各个食物都会得到一定的满意度,有些食物如果在某些食物之后吃还会增加满意度,问怎么吃满意度最高. dp[S][i]表示已经吃掉的食物集合是S且刚吃的是第i个食物的最大满意度 ..没什么好说的 1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 5 int val[18],pairs[18][18]; 6 long long d[1<<18][18]; 7 8

Codeforces Round #321 (Div. 2) A, B, C, D, E

580A. Kefa and First Steps 题目链接: A. Kefa and First Steps 题意描述: 给出一个序列,求最长公共子序列多长? 解题思路: 水题,签到 代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 using namespace std; 6 7 int main () 8 { 9 in