Pursuit追击

Pursuit追击

time limit per test: 2 seconds
每次测试的时间限制:2秒

memory limit per test:512 megabytes
每次测试的内存限制:512兆字节

input: standard input
输入:标准输入

output: standard output
产出:标准产出

You and your friend llya are participating in an individual programming contest consistig of mutiple stages.A conlestat can get between0
你和你的朋友伊利亚正在参加一个个人编程竞赛,这是一个多阶段的竞赛。

and 100 points,inclusive, for each stage, independently of other contestants.
和100分,包括,每个阶段,独立于其他参赛者。

Points received by contestants in different stages are used for forming overall contest results. Suppose that k stages of the contest are
参赛者在不同阶段获得的积分用于形成整体比赛结果。假设比赛的k个阶段是

completed.For each contestant k-[匀]stages with the highest scores are selected,and these scores are added up.This sum is the overa
每个选手都选择得分最高的k-[匀]级,并将这些分数相加。

result of the contestant. (Here[t]denotes rounding t down to the nearest integer.)
result of the contestant. (Here[t]denotes rounding t down to the nearest integer.)

For example, suppose 9 stages are completed, and your scores are 50,30,50,50,100,10,30,100,50.First,7 stages with the highest
For example, suppose 9 stages are completed, and your scores are 50,30,50,50,100,10,30,100,50.First,7 stages with the highest

scores are chosen—for example, all stages except for the 2-nd and the 6-th can be chosen.Then your overall resut is equal to
选择分数-例如,除第2和第6之外的所有阶段都可以选择,那么你的整体成绩等于

50+50+50+100.30100+50—430.
50+50+50+100.30100+50—430.

As of now, n stages are completed, and you know the points you and lya got for these stages.However it is unknown how many more stages
到目前为止,n个阶段已经完成,你知道你和莱娅在这些阶段得到了什么,但是还不知道还有多少阶段

will be held.You wonder what the smallest number of additional stages is, after which your result might become greater than or equal tolya’s
你想知道什么是最小的额外阶段,在此之后,你的结果可能会超过或等于托尔雅的

result,at least in theory. Find this number!
result,at least in theory. Find this number!

Input
输入

Each test contains mutiple test cases.The firt line contains the number of test cases t(1<t<1000).Description of the test cases follows.
每个测试包含多个测试用例。第一行包含测试用例的数量t(1<t<1000)。测试用例描述如下。

The first line of each test case contains a single integer n(1<n<105)—the number of completed stages.
每个测试用例的第一行包含一个整数n(1<n<105)–完成阶段的数目。

The second line contains n integers , agy… ,an(0<;≤100)— your points for the completed stages.
第二行包含n个整数,AGY.,A(0<;≤100)-完成阶段的积分。

The third line contains n integers b,b2,…,bn(0≤b<100)—llya’s points for the completed stages.
第三行包含n个整数b,b2,…,bn(0≤b<100)-Llya‘s点。

lt is guaranteed that the sum of n over all test cases does not exceed 105.
保证所有测试用例的n之和不超过105。

Output
输出量

For each test case print a single integer —-the smallest number of aditional stages required for your result to be able to become greater than
对于每个测试用例,打印一个整数??最小数量的调整阶段,以便您的结果能够大于。

or equal to llya’s result.
或者等于伊利亚的结果。

lf your result is already not less than llya’s result, print 0.
如果你的结果已经不少于伊利亚的结果,打印0。

模拟

#include<iostream>
#include<algorithm>
using namespace std;
int a[100001], b[100001];
int main()
{
 
	int t;
	cin >> t;
	while (t--)
	{
		int n;
		cin >> n;
		for (int i = 0; i < n; ++i)
		{
			cin >> a[i];
		}
		for (int i = 0; i < n; ++i)
		{
			cin >> b[i];
		}
		sort(a, a + n);
		sort(b, b + n);
		int sum1=0, sum2=0;
		for (int i=n/4; i < n; ++i)
		{
			sum1+=a[i];
			sum2+=b[i];
		}
		if (sum1 >= sum2)
		{
			cout << 0 << endl;
			continue;
		}
		int p1=n/4,p2=p1-1;
		int k = 0;
		while (sum1 < sum2)
		{
			sum1+=100;
			k++;
			if ( (k + n) % 4 != 0)
			{
				if(p2>=0)sum2 += b[p2],--p2;
			}
			else
			{
				if (p1 < n)sum1 -= a[p1], ++p1;
				else sum1 -= 100;
			}
			//cout << sum2 << '*' << sum1 << endl;
		}
 
		cout << k << endl;
	}
	return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值