Contest for Robots CodeForces - 1321A(二分)

Polycarp is preparing the first programming contest for robots. There are n problems in it, and a lot of robots are going to participate in it. Each robot solving the problem i gets pi points, and the score of each robot in the competition is calculated as the sum of pi over all problems i solved by it. For each problem, pi is an integer not less than 1.

Two corporations specializing in problem-solving robot manufacturing, “Robo-Coder Inc.” and “BionicSolver Industries”, are going to register two robots (one for each corporation) for participation as well. Polycarp knows the advantages and flaws of robots produced by these companies, so, for each problem, he knows precisely whether each robot will solve it during the competition. Knowing this, he can try predicting the results — or manipulating them.

For some reason (which absolutely cannot involve bribing), Polycarp wants the “Robo-Coder Inc.” robot to outperform the “BionicSolver Industries” robot in the competition. Polycarp wants to set the values of pi in such a way that the “Robo-Coder Inc.” robot gets strictly more points than the “BionicSolver Industries” robot. However, if the values of pi will be large, it may look very suspicious — so Polycarp wants to minimize the maximum value of pi over all problems. Can you help Polycarp to determine the minimum possible upper bound on the number of points given for solving the problems?

Input
The first line contains one integer n (1≤n≤100) — the number of problems.

The second line contains n integers r1, r2, …, rn (0≤ri≤1). ri=1 means that the “Robo-Coder Inc.” robot will solve the i-th problem, ri=0 means that it won’t solve the i-th problem.

The third line contains n integers b1, b2, …, bn (0≤bi≤1). bi=1 means that the “BionicSolver Industries” robot will solve the i-th problem, bi=0 means that it won’t solve the i-th problem.

Output
If “Robo-Coder Inc.” robot cannot outperform the “BionicSolver Industries” robot by any means, print one integer −1.

Otherwise, print the minimum possible value of maxi=1npi, if all values of pi are set in such a way that the “Robo-Coder Inc.” robot gets strictly more points than the “BionicSolver Industries” robot.

Examples
Input
5
1 1 1 0 0
0 1 1 1 1
Output
3
Input
3
0 0 0
0 0 0
Output
-1
Input
4
1 1 1 1
1 1 1 1
Output
-1
Input
9
1 0 0 0 0 0 0 0 1
0 1 1 0 1 1 1 1 0
Output
4
Note
In the first example, one of the valid score assignments is p=[3,1,3,1,1]. Then the “Robo-Coder” gets 7 points, the “BionicSolver” — 6 points.

In the second example, both robots get 0 points, and the score distribution does not matter.

In the third example, both robots solve all problems, so their points are equal.
思路:最大值最小化,二分的基本套路。二分最大值之后,对自己无利的条件直接设成1就可以了。
代码如下:

#include<bits/stdc++.h>
#define ll long long
using namespace std;

const int maxx=1e2+10;
int a[maxx],b[maxx];
int n;

inline bool check(int m)
{
	int max1=0,max2=0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]&&!b[i]) max1+=m;
		else if(a[i]&&b[i])max1+=1,max2+=1;
		else if(!a[i]&&b[i]) max2+=1;
		else ;
	}
	return max1>max2;
}

int main()
{
	while(~scanf("%d",&n))
	{
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		for(int i=1;i<=n;i++) scanf("%d",&b[i]);
		int l=1,r=1e7,mid;
		int ans=-1;
		while(l<=r)
		{
			mid=l+r>>1;
			if(check(mid))
			{
				ans=mid;
				r=mid-1;
			}
			else l=mid+1;
		}
		cout<<ans<<endl;
	}
	return 0;
}

努力加油a啊,(o)/~

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

starlet_kiss

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值