51nod 1297

来源:互联网 发布:电话录音软件 编辑:程序博客网 时间:2024/06/16 05:08
思路:
搞个栈模拟一下,也才5w;
直接wa1了。。然后想到井口如果都进不去那就。。。一定GG了。

所以维护一下从井口到井底是非递增的就好了;

#include <cstdio>#include <cstring>#include <cstdlib>#include <algorithm>#include <stack>#include <queue>using namespace std;stack<int>q;int n,m;int main(){    int u,x;    int tmp=1e9+1;    scanf("%d%d",&n,&m);    while(n--)    {        scanf("%d",&x);        if(tmp>=x)        {            q.push(x);            tmp=x;        }        else        {            x=tmp;            q.push(x);        }    }    int ans=0;    while(m)    {        scanf("%d",&x);        m--;        while(!q.empty()&&q.top()<x)            q.pop();        if(!q.empty())        {            q.pop();            ans++;        }    }    printf("%d\n",ans);    return 0;}


0 0