n 个同学去动物园参观,原本每人都需要买一张门票,但售票处推出了一个优惠活动,一个体重为 xx 的人可以和体重至少为 2x2x 配对,这样两人只需买一张票。现在给出了 nn 个人的体重,请你计算他们最少需要买几张门票?
输入格式
第一行一个整数 nn,表示人数。
第二行 nn 个整数,每个整数 a_iai 表示每个人的体重。
输出格式
一个整数,表示最少需要购买的门票数目。
数据范围
对于 30\%30% 的数据:1 \le n \le 251≤n≤25,1\le a_i \le 1001≤ai≤100。
对于 60\%60% 的数据:1 \le n \le 100001≤n≤10000,1\le a_i \le 10001≤ai≤1000。
对于 100\%100% 的数据:1 \le n \le 5\cdot 10^51≤n≤5⋅105,1\le a_i \le 10^51≤ai≤105。
样例解释
11 和 99 配对,77 和 33 配对,剩下 5,55,5 单独,一共买四张票。
Sample 1
Inputcopy | Outputcopy |
---|---|
6 1 9 7 3 5 5 | 4 |
AC
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int a[500500];
int main(void)
{
int n,ans=0;
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
sort(a+1,a+n+1);
for(int i=n/2,j=n;i>=1&&j>n/2;)
{
if(a[i]*2<=a[j])
{
i--,j--;
ans++;
}
else
i--;
}
cout<<n-ans<<endl;
return 0;
}