您的位置:首页 > 其它

CF - 580A. Kefa and First Steps - dp思维

2017-05-06 14:19 387 查看
1.题目描述:

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
4000
fifth one.

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

2.题意概述:
给你一组数组,要你最长的连续非递减子串的长度。

3.解题思路:

既然是连续,考虑dp思想,以i结尾最大的连续子串长度就和当前a[i]的值相关。因此记录一下当前递增的值即可。

4.AC代码:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define maxn 100100
#define lson root << 1
#define rson root << 1 | 1
#define lent (t[root].r - t[root].l + 1)
#define lenl (t[lson].r - t[lson].l + 1)
#define lenr (t[rson].r - t[rson].l + 1)
#define N 1111
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
using namespace std;
const int mod = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
int a[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
freopen("out.txt", "w", stdout);
long _begin_time = clock();
#endif
int n;
while (~scanf("%d", &n))
{
int ans = 0;
int cur = 0, now = 0;
for (int i = 0; i < n; i++)
{
scanf("%d", &a[i]);
if (a[i] >= now)
{
cur++;
ans = max(ans, cur);
}
else
cur = 1;
now = a[i];
}
printf("%d\n", ans);
}
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm codeforces