最好还是用堆来维护吧,幸亏没超时。

# include <stdio.h>

int top, s[30005];

int main()
{    
    int n, h, i ,find, cur, mini;
    while (~scanf("%d", &n))
    {
        top = 0;
        for (i = 1; i <= n; ++i)
        {
            scanf("%d", &h);
            find = 0;
            for (int i = 0; i < top; ++i)
            {
                if (s[i] > h)
                {
                    if (!find)
                        find = 1, cur = s[i], mini = i;
                    else if (cur > s[i])
                    {
                        cur = s[i];
                        mini = i;
                    }                                            
                }
            }
            if (!find)
                s[top++] = h;
            else
                s[mini] = h;            
        }
        printf("%d\n", top);
    }
    
    return 0;
}

相关文章:

  • 2021-05-16
  • 2021-12-26
  • 2022-12-23
  • 2018-07-29
  • 2019-06-18
  • 2022-01-23
  • 2021-12-30
猜你喜欢
  • 2021-05-27
  • 2022-01-28
  • 2021-06-30
相关资源
相似解决方案