zoukankan      html  css  js  c++  java
  • codeforces387B

    George and Round

     CodeForces - 387B 

    George decided to prepare a Codesecrof round, so he has prepared m problems for the round. Let's number the problems with integers 1 through m. George estimates the i-th problem's complexity by integer bi.

    To make the round good, he needs to put at least n problems there. Besides, he needs to have at least one problem with complexity exactly a1, at least one with complexity exactly a2, ..., and at least one with complexity exactly an. Of course, the round can also have problems with other complexities.

    George has a poor imagination. It's easier for him to make some already prepared problem simpler than to come up with a new one and prepare it. George is magnificent at simplifying problems. He can simplify any already prepared problem with complexity c to any positive integer complexity d (c ≥ d), by changing limits on the input data.

    However, nothing is so simple. George understood that even if he simplifies some problems, he can run out of problems for a good round. That's why he decided to find out the minimum number of problems he needs to come up with in addition to the mhe's prepared in order to make a good round. Note that George can come up with a new problem of any complexity.

    Input

    The first line contains two integers n and m (1 ≤ n, m ≤ 3000) — the minimal number of problems in a good round and the number of problems George's prepared. The second line contains space-separated integers a1, a2, ..., an (1 ≤ a1 < a2 < ... < an ≤ 106) — the requirements for the complexity of the problems in a good round. The third line contains space-separated integers b1, b2, ..., bm (1 ≤ b1 ≤ b2... ≤ bm ≤ 106) — the complexities of the problems prepared by George.

    Output

    Print a single integer — the answer to the problem.

    Examples

    Input
    3 5
    1 2 3
    1 2 2 3 3
    Output
    0
    Input
    3 5
    1 2 3
    1 1 1 1 1
    Output
    2
    Input
    3 1
    2 3 4
    1
    Output
    3

    Note

    In the first sample the set of the prepared problems meets the requirements for a good round.

    In the second sample, it is enough to come up with and prepare two problems with complexities 2 and 3 to get a good round.

    In the third sample it is very easy to get a good round if come up with and prepare extra problems with complexities: 2, 3, 4.

    sol:注意到n很小,n2都可以过,于是直接暴力模拟。

    我猜应该有O(n*logn)的做法,比方说开一个multiset,先排遍序,每次取大于等于当前这个数的第一个,然后弹掉(这只是嘴巴,我没写过)

    #include <bits/stdc++.h>
    using namespace std;
    typedef int ll;
    inline ll read()
    {
        ll s=0;
        bool f=0;
        char ch=' ';
        while(!isdigit(ch))
        {
            f|=(ch=='-'); ch=getchar();
        }
        while(isdigit(ch))
        {
            s=(s<<3)+(s<<1)+(ch^48); ch=getchar();
        }
        return (f)?(-s):(s);
    }
    #define R(x) x=read()
    inline void write(ll x)
    {
        if(x<0)
        {
            putchar('-'); x=-x;
        }
        if(x<10)
        {
            putchar(x+'0');    return;
        }
        write(x/10);
        putchar((x%10)+'0');
        return;
    }
    #define W(x) write(x),putchar(' ')
    #define Wl(x) write(x),putchar('
    ')
    const int N=3005;
    int n,m,a[N],b[N];
    bool Bo[N];
    int main()
    {
        int i,j,ans;
        R(n); R(m);
        ans=n;
        for(i=1;i<=n;i++) R(a[i]);
        for(i=1;i<=m;i++) R(b[i]);
        sort(b+1,b+m+1);
        for(i=1;i<=n;i++)
        {
            for(j=1;j<=m;j++) if(b[j]>=a[i]&&(!Bo[j]))
            {
                Bo[j]=1; ans--; break;
            }
        }
        Wl(ans);
        return 0;
    }
    View Code
  • 相关阅读:
    python基础-第十二篇-12.1jQuery基础与实例
    python基础-第十一篇-11.2DOM为文档操作
    [LC] 170. Two Sum III
    [Algo] 11. Rainbow Sort
    [LC] 31. Next Permutation
    [LC] 994. Rotting Oranges
    [LC] 863. All Nodes Distance K in Binary Tree
    [Algo] 132. Deep Copy Undirected Graph
    [LC] 138. Deep Copy Linked List With Random Pointer
    [Algo] 118. Array Deduplication IV
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10629378.html
Copyright © 2011-2022 走看看