Educational codeforces Round C. Boxes Packing

Source: Internet
Author: User
Tags time limit


Original question:
C. Boxes Packing
Time limit per test1 second
Memory limit per test256 megabytes
Inputstandard input
Outputstandard output
Mishka has got n empty boxes. For every I (1≤i≤n), i-th Box was a cube with side length AI.



Mishka can put a box I into another box J if the following conditions is met:



I-th box is isn't put into another box;
j-th box doesn ' t contain any other boxes;
Box I is smaller than box J (Ai < AJ).
Mishka can put boxes into each other an arbitrary number of times. He wants to minimize the number of visible boxes. A box is called visible iff it isn't put into some another box.



Help Mishka to determine the minimum possible number of visible boxes!



Input
The first line contains one integer n (1≤n≤5000)-the number of boxes Mishka have got.



The second line contains n integers a1, a2, ..., an (1≤ai≤109), where AI is the side length of i-th box.



Output
Print the minimum possible number of visible boxes.



Examples
Input
3
1 2 3
Output
1
Input
4
4 2 4 3
Output
2
Note
In the first example it's possible to put box 1 into Box 2, and 2 into 3.



In the second example Mishka can put box 2 to box 3, and box 4 into box 1.



English:
Here you have n boxes, each with a size AI, and a large box to fit the small box. Now ask how many boxes you can have left in case you try to pack the boxes.


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
struct box
{
    int s;
    bool in;
    box()
    {
        s=0;
        in=false;
    }
};
box b[5001];
int cmp(const box &b1,const box &b2)
{
    return b1.s<b2.s;
}
int main()
{
    ios::sync_with_stdio(false);
    int n;
    while(cin>>n)
    {
        memset(b,0,sizeof(box));
        for(int i=1;i<=n;i++)
        {
            cin>>b[i].s;
            b[i].in=false;
        }
        sort(b+1,b+1+n,cmp);
        int cnt=n;
        for(int i=1;i<=n;i++)
        {
            int tmp=i;
            if(b[i].in)
                continue;
            for(int j=i+1;j<=n;j++)
            {
                if(b[j].s>b[tmp].s&&!b[j].in)
                {
                    b[j].in=1;
                    tmp=j;
                    cnt--;
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}


Answer:



According to the box size from small to large, small boxes in a slightly larger box than it, the box is marked with a box, and finally check the number of boxes left to go.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.