CF 253B(队列上维护2个指针后移)

B. 实验误差
time limit per test
1 second
memory limit per test
256 megabytes
input
input.txt
output
output.txt

小明做实验,测了n次结果,因为误差,这些结果不一样。

至少修改多少结果,才能使最大的结果不超过最小的结果的2倍?

Input

第一行一个整数 n (2 ≤ n ≤ 105),第二行有n个数c1, c2, ..., cn表示结果(1 ≤ ci ≤ 5000)

Output

输出一个整数,表示最小修改次数。

Sample test(s)
input
6
4 5 3 8 3 7
output
2
input
4
4 3 2 4
output
0
Note

第1个数据删除8,7,第二个数据本身就满足条件。


排序,从小到大枚举最小数,并把后指针挪向最大的不用修改的数进行统计即可。


#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<iostream>
using namespace std;
#define MAXN (100000+100)
int a[MAXN];
int n;
int main()
{
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	a[n+1]=1000000;
//	for (int i=1;i<=n;i++) cout<<a[i]<<' ';cout<<endl;
	int t=1,ans=0;
	for (int h=1;h<=n;h++)
	{
		while (a[h]*2>=a[t+1]) t++;
		ans=max(ans,t-h+1);
	}
	cout<<n-ans<<endl;
	
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值