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][10,20,30,40], we can permute it so that it becomes [20,40,10,30][20,40,10,30]. Then on the first and the second positions the integers became larger (20>1020>10, 40>2040>20) and did not on the third and the fourth, so for this permutation, the number that Vasya wants to maximize equals 22. 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.

Input

The first line contains a single integer nn (1≤n≤1051≤n≤105) — the length of the array.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) — the elements of the array.

Output

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.

Examples
input

Copy
7
10 1 1 1 5 5 3
output

Copy
4
input

Copy
5
1 1 1 1 1
output

Copy
0
Note

In the first sample, one of the best permutations is [1,5,5,3,10,1,1][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的贡献,问你最大能有多少贡献。

 #include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
using namespace std;
const int maxn = int(1e5) + ;
int a[maxn], n, r = , ans;
int main()
{
cin >> n;
for (int i = ; i <= n; i++)
cin >> a[i];
sort(a+ , a+ + n);
for (int i = ; i <= n; i++)
{
while (r <= n && a[r] <= a[i])
r++;
if (r <= n)
ans++, r++;
}
cout << ans << std::endl;
return ;
}

A. Reorder the Array的更多相关文章

  1. CF 1008C Reorder the Array

    You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it ...

  2. Codeforces Round #497 (Div. 2) C. Reorder the Array

    Bryce1010模板 http://codeforces.com/contest/1008/problems #include <bits/stdc++.h> using namespa ...

  3. CodeForces-1007A Reorder the Array 贪心 田忌赛马

    题目链接:https://cn.vjudge.net/problem/CodeForces-1007A 题意 给个数组,元素的位置可以任意调换 问调换后的元素比此位置上的原元素大的元素个数最大多少 思 ...

  4. CF1007A Reorder the Array 题解

    To CF 这道题是排序贪心,将原序列排序后统计答案即可. 但是直接统计会超时,因为排序后具有单调性,所以可以进行一点优化,这样,便可以通过此题. 而这道题的优化在于单调性,因为 \(a[i+1]\) ...

  5. 29.调整数组顺序使奇数位于偶数前面[ReOrderArray]

    [题目] 输入一个整数数组,调整数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位于数组的后半部分.要求时间复杂度为O(n). [分析] 如果不考虑时间复杂度,最简单的思路应该是从头扫描这个 ...

  6. 剑指offer题目java实现

    Problem2:实现Singleton模式 题目描述:设计一个类,我们只能生成该类的一个实例 package Problem2; public class SingletonClass { /* * ...

  7. 2018SDIBT_国庆个人第一场

    A - Turn the Rectangles CodeForces - 1008B There are nn rectangles in a row. You can either turn eac ...

  8. Codeforces Round #169 (Div. 2) A水 B C区间更新 D 思路

    A. Lunch Rush time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  9. CF 276C Little Girl and Maximum Sum【贪心+差分】

    C. Little Girl and Maximum Sum time limit per test2 seconds memory limit per test256 megabytes input ...

随机推荐

  1. StartDT AI Lab | 视觉智能引擎+数据决策引擎——打造商业“智能沙盘”

    众所周知,线上商家可以通过淘宝平台的大量前端“埋点”轻松获取商品的加购率.收藏率.转化率.成交额等大量基础信息,甚至商家能够在更精细的层面,获取商品关键字变化或者上新/爆款带来的流量变化数据,更甚者商 ...

  2. 第19届亚太零售商大会 | 奇点云CEO行在受邀出席发表演讲

    2019年9月5日—7日,第19届亚太零售商大会在重庆举行. 亚太零售商大会作为世界三大零售盛会之一,是亚太地区零售行业最具规模.最具影响力的零售行业盛会.本次大会以“新零售·新消费·新动力·合作与共 ...

  3. Linux_实验1 Red Hat的使用

    目录 使用rjxy用户登录图形界面 由当前控制台切换到tty4虚拟控制台: 由当前用户切换到root用户: 用root用户查看当前运行级别,并把当前运行级别切换到3级,再切换到5级运行级别: 用“ge ...

  4. 谷歌眼镜、亚马逊音箱,5G时代隐私或将面临更大颠覆

    别看现在的智能手机.平板电脑.可穿戴设备.智能家居等那么火爆,但离开网络它们其实什么也不是.当然,智能终端设备的迭进也是与网络制式不断向前演变相辅相成的,二者算是互相成就.不过也由此衍生出很多问题,尤 ...

  5. 爬虫之使用requests爬取某条标签并生成词云

    一.爬虫前准备 1.工具:pychram(python3.7) 2.库:random,requests,fake-useragent,json,re,bs4,matplotlib,worldcloud ...

  6. Netflix拒上戛纳电影节,能给国内视频产业什么启示?

    当新事物诞生时,总是会遭到质疑,甚至是排斥!因为新事物的活力.潜力,都对保守的传统事物产生了极大的冲击.就像有声电影刚刚诞生时,一代"默片大师"卓别林就对其进行了激烈的反对.他认为 ...

  7. 无人工地,原来是靠AI这样运行的

    随着全世界逐渐进入老龄化社会,适龄工作人口将急剧减少,必然导致用工成本增加,施工方降低人工成本.提升施工效率和质量的需求会越来越强烈,数字化施工技术应用前景广阔.在过去的十年中,无人机迎来了自己发展的 ...

  8. cesium入门示例-探测效果

    动画实现方式通过多个canvas实现,参考的https://www.yueyanshaosun.cn/ysCesium/views/5_geometricObj2_entityCanvas.html ...

  9. 吴裕雄--python学习笔记:爬虫基础

    一.什么是爬虫 爬虫:一段自动抓取互联网信息的程序,从互联网上抓取对于我们有价值的信息. 二.Python爬虫架构 Python 爬虫架构主要由五个部分组成,分别是调度器.URL管理器.网页下载器.网 ...

  10. python保留2位小数

    1 代码: ​ 2 运行结果: ​ 3 其中字符串形式的:print('%.2f' % (x/y))方式最好