Codeforces 651B Beautiful Paintings

来源:互联网 发布:二式大艇数据 编辑:程序博客网 时间:2024/05/16 04:50
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
520 30 10 50 40
output
4
input
4200 100 100 200
output

2



从很久很久以前,那里有一个画展,画展有n幅画,第i幅画有一个美丽指数ai我们知道的是,一个当游览者从一张画到一张美丽指数更高的画的时候,会变得开心。

画将会一列的排放,我们可以随意安排画的顺序。那么如果游览者以从头到尾的顺序游览的画,总共最多可以变开心多少次呢。

换而言之,我们需要将美丽指数重新排列,使得有最多的i (1 ≤ i ≤ n - 1), 符合 ai + 1 > ai输出符合条件的i的数目。  

#include <stdio.h>  #include <stdlib.h>  int sort(const void* a,const void* b)  {      return *(int*)a-*(int*)b;  }  int main()  {      int n;      int array[1000];      while(scanf("%d",&n)!=EOF){          for(int i=0;i<n;i++)              scanf("%d",&array[i]);          qsort(array,n,sizeof(int),sort);          int now;          int count=0;          for(int j=0;j<=n-1;j++){              if(array[j]!=0){                  now=array[j];                  array[j]=0;                  for(int k=j+1;k<=n-1;k++)                     if(array[k]!=0&&array[k]>now){                          count++;                          now=array[k];                          array[k]=0;                       }               }          }          printf("%d\n\n",count);      }      return 0;  }  


0 0
原创粉丝点击