zoukankan      html  css  js  c++  java
  • CodeForces999A-Mishka and Contest

    A. Mishka and Contest
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Mishka started participating in a programming contest. There are nn problems in the contest. Mishka's problem-solving skill is equal to kk.

    Mishka arranges all problems from the contest into a list. Because of his weird principles, Mishka only solves problems from one of the ends of the list. Every time, he chooses which end (left or right) he will solve the next problem from. Thus, each problem Mishka solves is either the leftmost or the rightmost problem in the list.

    Mishka cannot solve a problem with difficulty greater than kk. When Mishka solves the problem, it disappears from the list, so the length of the list decreases by 11. Mishka stops when he is unable to solve any problem from any end of the list.

    How many problems can Mishka solve?

    Input

    The first line of input contains two integers nn and kk (1n,k1001≤n,k≤100) — the number of problems in the contest and Mishka's problem-solving skill.

    The second line of input contains nn integers a1,a2,,ana1,a2,…,an (1ai1001≤ai≤100), where aiai is the difficulty of the ii-th problem. The problems are given in order from the leftmost to the rightmost in the list.

    Output

    Print one integer — the maximum number of problems Mishka can solve.

    Examples
    input
    Copy
    8 4
    4 2 3 1 5 1 6 4
    
    output
    Copy
    5
    
    input
    Copy
    5 2
    3 1 2 1 3
    
    output
    Copy
    0
    
    input
    Copy
    5 100
    12 34 55 43 21
    
    output
    Copy
    5
    
    Note

    In the first example, Mishka can solve problems in the following order: [4,2,3,1,5,1,6,4][2,3,1,5,1,6,4][2,3,1,5,1,6][3,1,5,1,6][1,5,1,6][5,1,6][4,2,3,1,5,1,6,4]→[2,3,1,5,1,6,4]→[2,3,1,5,1,6]→[3,1,5,1,6]→[1,5,1,6]→[5,1,6], so the number of solved problems will be equal to 55.

    In the second example, Mishka can't solve any problem because the difficulties of problems from both ends are greater than kk.

    In the third example, Mishka's solving skill is so amazing that he can solve all the problems.

    ac代码;

    #include<bits/stdc++.h>
    using namespace std;


    int main()
    {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k,a[110],flag1,flag2,cnt=0;
    cin>>n>>k;
    flag1=1,flag2=n;
    for(int i=1;i<=n;i++) cin>>a[i];


    while(flag1<=flag2)
    {
    while(a[flag1]<=k && flag1<=flag2)
    {
    cnt++;
    flag1++;
    }
    while(a[flag2]<=k && flag1<=flag2)
    {
    cnt++;
    flag2--;
    }
    if(a[flag1]>k&&a[flag2]>k) break;
    }

    cout<<cnt<<endl;

    return 0;
    }





  • 相关阅读:
    6.VUE事件处理
    springmvc在使用@ModelAttribute注解获取Request和Response会产生线程并发不安全问题
    IDEAhttp://lookdiv.com/index/index/indexcodeindex.html
    不四舍五入保留...4(round(273.86015,4,1);)
    spring security中@PreAuthorize、@PostAuthorize、@PreFilter和@PostFilter四者的区别
    @RepeatSubmit spring boot 防止重复提交
    权限设计的杂谈
    vue设置全局样式变量 less
    坐标轴刻度取值算法-基于魔数数组-源于echarts的y轴刻度计算需求
    less使用
  • 原文地址:https://www.cnblogs.com/csushl/p/9386539.html
Copyright © 2011-2022 走看看