CF1007A.Reorder the Array
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such integers.
For instance, if we are given an array [10,20,30,40], we can permute it so that it becomes [20,40,10,30]. Then on the first and the second positions the integers became larger (20>10, 40>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 2. Read the note for the first example, there is one more demonstrative test case.
Help Vasya to permute integers in such way that the number of positions in a new array, where integers are greater than in the original one, is maximal.
给你一个整数数组。瓦夏可以对其元素进行重排(即改变元素的顺序)。他希望以某种方式重排,使得尽可能多的整数被放置在原本数值更小的整数所在的位置上。请帮助瓦夏找出这种位置的最大可能数量。
例如,若给定数组 [10,20,30,40],我们可以将其重排为 [20,40,10,30]。此时,第一和第二个位置上的整数变大了(20>10,40>20),而第三和第四个位置上的整数并未变大,因此对于该排列,瓦夏希望最大化的数值等于 2。请参阅第一个样例的注释,其中还给出了另一个具有说明性的测试用例。
请帮助瓦夏以某种方式重排这些整数,使得新数组中满足“该位置上的整数大于原数组中对应位置上的整数”的位置数量达到最大。
输入格式
The first line contains a single integer n (1≤n≤105) — the length of the array.
The second line contains n integers a1,a2,…,an (1≤ai≤109) — the elements of the array.
第一行包含一个整数 n(1≤n≤105)—— 数组的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 数组的元素。
输出格式
Print a single integer — the maximal number of the array's elements which after a permutation will stand on the position where a smaller element stood in the initial array.
输出一个整数——表示数组中最多有多少个元素,在经过一次排列后,能够处于初始数组中比它更小的元素所在的位置。
输入输出样例
输入#1
7 10 1 1 1 5 5 3
输出#1
4
输入#2
5 1 1 1 1 1
输出#2
0
说明/提示
In the first sample, one of the best permutations is [1,5,5,3,10,1,1]. On the positions from second to fifth the elements became larger, so the answer for this permutation is 4.
In the second sample, there is no way to increase any element with a permutation, so the answer is 0.
在第一个样例中,一个最优排列是 [1,5,5,3,10,1,1]。从第二个位置到第五个位置,元素值变大了,因此该排列的答案为 4。
在第二个样例中,无法通过任何排列使任意元素增大,因此答案为 0。
输入解题思路,AI测评打分。不知道怎么写?