Codeforces 651 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.

题意就是游客在欣赏画时,通常会因为当前这幅画比前一幅画美丽而获得一点幸福度。 给出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
",ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/ZERO-/p/9692704.html