zoukankan      html  css  js  c++  java
  • CF div2 321 A

    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.

    Sample test(s)
    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.

    我居然上来就想套LIS的模板。。。我*了狗。。。然后发现读错题,扫一遍就行了。。

     1 #include <cstdio>
     2 #include <cstring>
     3 #include <iostream>
     4 #include <stack>
     5 #include <queue>
     6 #include <map>
     7 #include <algorithm>
     8 #include <vector>
     9 
    10 using namespace std;
    11 
    12 const int maxn = 1000005;
    13 
    14 typedef long long LL;
    15 
    16 vector<int>G[maxn];
    17 
    18 int a[maxn];
    19 int dp[maxn];
    20 
    21 
    22 int main()
    23 {
    24     int n,m;
    25     int tmp = 1;
    26     scanf("%d",&n);
    27     for(int i=1;i<=n;i++){
    28         scanf("%d",&a[i]);
    29     }
    30     int cnt = 1;
    31     int ans = 0;
    32     while(cnt<=n){
    33         if(a[cnt]<=a[cnt+1]){
    34             tmp++;
    35         }
    36        else if (a[cnt]>a[cnt+1]){
    37             tmp  = 1;
    38         }
    39         ans = max(tmp,ans);
    40         cnt++;
    41     }
    42 
    43 
    44 
    45 
    46     printf("%d
    ",ans);
    47 
    48 
    49     return 0;
    50 }
    View Code
  • 相关阅读:
    IO多路复用
    Elasticsearch之打分机制、集群搭建、脑裂问题
    Elasticsearch之-映射管理,ik分词器
    Elasticsearch之高亮查询,聚合查询
    Elasticsearch之索引、文档、组合查询、排序查询、filter过滤操作
    Go 数组、切片、Maps
    Go if-else语句、for循环、switch语句
    Go 函数、包、mode模式
    毕业设计-1.05
    毕业设计-1.04
  • 原文地址:https://www.cnblogs.com/lmlyzxiao/p/4834056.html
Copyright © 2011-2022 走看看