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.

题意就是游客在欣赏画时,通常会因为当前这幅画比前一幅画美丽而获得一点幸福度。 给出n副画作的美丽值,现在要将他们排成一行。求出游客能获得的最大幸福值。

我想的就是找出美丽值最多的那个数,把剩下的所有的值都和这个最多的数值比较,反正要么比这个数大,要么比这个数小,都可以的。

不会什么优先队列之类的,药丸。。。只会怎么想的就怎么写,也不知道自己写的啥。。。

代码:

#include<bits/stdc++.h>
using namespace std;
bool cmp(int x,int y){
return x>y;
}
int main(){
int n,ans,a[1050],b[1050];
while(~scanf("%d",&n)){
ans=0;
memset(b,0,sizeof(b));
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
b[a[i]]++;
}
sort(b,b+1050,cmp); //这里就是排序把最多的那个数的次数放在最前面,把剩下的加起来就可以了。
for(int i=1;i<1050;i++)
ans+=b[i];
printf("%d\n",ans);
}
return 0;
}

Codeforces 651 B. Beautiful Paintings的更多相关文章

  1. codeforces 651B B. Beautiful Paintings

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. 【CodeForces 651B】Beautiful Paintings 排序+贪心

    题目大意: 给定集合,对于任意一个的排列,记,求. 很明显每次搞出一个长度为的最长上升序列,然后把元素给删掉,答案增加. 直接暴力需要. 但是可以进行优化. 设有个,将个数从小到大排序,记为长度为的数 ...

  3. Codeforces Round #345 (Div. 2) B. Beautiful Paintings 暴力

    B. Beautiful Paintings 题目连接: http://www.codeforces.com/contest/651/problem/B Description There are n ...

  4. codeforces 651B Beautiful Paintings

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  5. Codeforces Round #345 (Div. 2)——B. Beautiful Paintings(贪心求上升序列个数)

    B. Beautiful Paintings time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. [codeforces 55]D. Beautiful numbers

    [codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...

  7. CodeForces 651B Beautiful Paintings 贪心

    A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  8. Beautiful Paintings CodeForces - 651B (贪心)

    大意: 给定序列$a$, 可以任意排序, 求最大下标i的个数, 满足$a_i<a_{i+1}$. 这个贪心挺好的, 答案就为n-所有数字出现次数最大值.

  9. Codeforces 651B Beautiful Paintings【贪心】

    题意: 给定序列,重新排序,使严格上升的子序列最多.求这些子序列总长度. 分析: 贪心,统计每个元素出现次数,每次从剩余的小的开始抽到大的,直到不再剩余元素. 代码: #include<iost ...

随机推荐

  1. 在.cs代码文件中无法识别控件

    原因:由于直接复制别人的网页文件到项目. 解决方案,自己右键,新建网页,再把控件代码复制到 aspx和 cs

  2. ARC074 E RGB Sequence DP

    ---题面--- 题解: 首先,有一个不太直观的状态,f[i][j][k][l]表示DP到i位,三种颜色最后出现的位置分别是j, k, l的方案数.因为知道了三种颜色最后出现的位置,因此也可以得知以当 ...

  3. BZOJ 4710 [Jsoi2011]分特产 解题报告

    4710 [Jsoi2011]分特产 题意 给定\(n\)个集合,每个集合有相同的\(a_i\)个元素,不同的集合的元素不同.将所有的元素分给\(m\)个不同位置,要求每个位置至少有一个元素,求分配方 ...

  4. js 日期获去及格式化

    原文地址:http://www.cnblogs.com/qinpengming/archive/2012/12/03/2800002.html Js获取当前日期时间及格式化操作 var myDate ...

  5. ActiveMQ(3) ActiveMQ创建(simpleAuthenticationPlugin)安全认证

    控制端安全认证: ActiveMQ目录conf下jetty.xml: <bean id="securityLoginService" class="org.ecli ...

  6. 链接oracle数据库 生成表对应的javabean

    package com.databi.utils; import java.io.File; import java.io.FileOutputStream; import java.io.IOExc ...

  7. 【bzoj1597- [Usaco2008 Mar]土地购买】斜率优化

    [597][Usaco2008 Mar]土地购买 [题目描述] 有N (1 <= N <= 50,000) 块长方形的土地. 每块土地的长宽满足(1 <= 宽 <= 1,000 ...

  8. 玩转Metasploit系列(第二集)

    在上一节的内容中,大家了解了Metasploit的结构.这一节我们主要介绍的是msfconsole的理论. msfconsole理论 在MSF里面msfconsole可以说是最流行的一个接口程序.很多 ...

  9. 生成器版本的文件MD5校验

    生成器是一个可迭代的对象,可以对可迭代的对象进行便利,比如字符串.列表等,都是可迭代对象   def f(n): for i in range(n): yield i   特点: 1.当调用这个函数的 ...

  10. KVM基本概念

    在kvm技术中,应用到的两个东西:qemu和kvm.其中kvm负责cpu虚拟化和内存虚拟化,但是kvm不能模拟其他设备,qemu是模拟IO设备(网卡,磁盘),kvm加上qemu之后就能实现真正意义上的 ...