B. Beautiful Paintings
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n pictures delivered for the new exhibition. The i-th painting has beauty ai. We know that a visitor becomes happy every time he passes from a painting to a more beautiful one.

We are allowed to arranged pictures in any order. What is the maximum possible number of times the visitor may become happy while passing all pictures from first to last? In other words, we are allowed to rearrange elements of a in any order. What is the maximum possible number of indices i (1 ≤ i ≤ n - 1), such that ai + 1 > ai.

Input

The first line of the input contains integer n (1 ≤ n ≤ 1000) — the number of painting.

The second line contains the sequence a1, a2, ..., an (1 ≤ ai ≤ 1000), where ai means the beauty of the i-th painting.

Output

Print one integer — the maximum possible number of neighbouring pairs, such that ai + 1 > ai, after the optimal rearrangement.

Examples
input
5
20 30 10 50 40
output
4
input
4
200 100 100 200
output
2
Note

In the first sample, the optimal order is: 10, 20, 30, 40, 50.

In the second sample, the optimal order is: 100, 200, 100, 200.

题意:求最多的上升序列的个数,用map比数组快多,做法:切蛋糕一样每次切一层

代码:

#include<iostream>
#include<algorithm>
#include<vector>
#include<sstream>
#include<map>
using namespace std;
int main(void)
{
int t,n,i,j,be,sum,ans;
while (cin>>n)
{
map<int,int>list;
for (i=0; i<n; i++)
{
cin>>be;
list[be]++;
}
ans=0;
while (n)//每次
{
int num=0;
for (map<int,int>::iterator it=list.begin(); it!=list.end(); it++)
{
if(it->second>0)
{
(it->second)--;
n--;
num++;
}
}
ans=ans+num-1;//两个以上才算一个上升序列
}
cout<<ans<<endl;
}
return 0;
}

最新文章

  1. 【WPF】值是枚举的RadioButton 绑定问题
  2. inux中shell截取字符串方法总结
  3. &#39;[&lt;NSObject 0x8a4b500&gt; setValue:forUndefinedKey:]
  4. nodejs http 请求延时的处理方法(防止程序崩溃)
  5. static NSString *ID的改进
  6. n条直线最多能将一个平面分成多少部分?
  7. 《OD大数据实战》Oozie环境搭建
  8. Quartz 2D画虚线-b
  9. 那天有个小孩跟我说LINQ(四)转载
  10. python针对于mysql的增删改查
  11. SQL-54 查找排除当前最大、最小salary之后的员工的平均工资avg_salary。
  12. JavaSE-类
  13. Windows 10 RS4 无法完全关闭Hyper-V导致Virtual Box 虚拟机无法启动
  14. Android转换集合数据(ArrayList)为Json格式并上传服务器
  15. Glide高级详解—缓存与解码复用
  16. 听闻 kubernetes,快速了解一番
  17. 3.8 C++继承机制下的析构函数
  18. 比特币测试网络搭建以及RPC服务开启-配置注意事项
  19. clion配置c/c++环境
  20. 查看内核页表kernel_page_tables (aarch32)

热门文章

  1. Centos7.3 安装devstack stein版本
  2. npm上发布包和删除已发布的npm包(https://www.npmjs.com/)
  3. mina架构在JT/T808协议应用程序中的应用
  4. oracle中的树状查询
  5. IOS版本判断
  6. retain, copy, assign以及autorelease
  7. React支持装饰器
  8. 201621123080 《Java程序设计》第13周学习总结
  9. 【Python学习之五】高级特性1(切片、迭代、列表生成器、生成器、迭代器)
  10. python入门:输出1-100之内的所有奇数和偶数