CF_37A_Towers

来源:互联网 发布:老年人意外伤害数据 编辑:程序博客网 时间:2024/06/06 19:36
A. Towers
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Vasya has received a young builder’s kit. The kit consists of several wooden bars, the lengths of all of them are known. The bars can be put one on the top of the other if their lengths are the same.

Vasya wants to construct the minimal number of towers from the bars. Help Vasya to use the bars in the best way possible.

Input

The first line contains an integer N (1 ≤ N ≤ 1000) — the number of bars at Vasya’s disposal. The second line containsN space-separated integers li — the lengths of the bars. All the lengths are natural numbers not exceeding1000.

Output

In one line output two numbers — the height of the largest tower and their total number. Remember that Vasya should use all the bars.

Sample test(s)
Input
31 2 3
Output
1 3
Input
46 5 6 7
Output
2 3

简单模拟,计数找最大值即可


#include <iostream>#include <stdio.h>#include <string.h>using namespace std;const int M=1005;int len[M];int main(){    int n,num;    int tot,lar,maxl;    while(scanf("%d",&n)!=EOF)    {        memset(len,0,sizeof(len));        maxl=tot=lar=0;        for(int i=0;i<n;i++)        {            scanf("%d",&num);            len[num]++;            maxl=max(maxl,num);        }        for(int i=1;i<=maxl;i++)        {            if(len[i])            {                  tot++;                  lar=max(lar,len[i]);            }        }        printf("%d %d\n",lar,tot);    }    return 0;}


0 0
原创粉丝点击