D. Zero Quantity Maximization

 D. Zero Quantity Maximization

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given two arrays aa and bb, each contains nn integers.

You want to create a new array cc as follows: choose some real (i.e. not necessarily integer) number dd, and then for every i∈[1,n]i∈[1,n] let ci:=d⋅ai+bici:=d⋅ai+bi.

Your goal is to maximize the number of zeroes in array cc. What is the largest possible answer, if you choose dd optimally?

Input

The first line contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of elements in both arrays.

The second line contains nn integers a1a1, a2a2, ..., anan (−109≤ai≤109−109≤ai≤109).

The third line contains nn integers b1b1, b2b2, ..., bnbn (−109≤bi≤109−109≤bi≤109).

Output

Print one integer — the maximum number of zeroes in array cc, if you choose dd optimally.

这道题目不难,但是有几个坑。

在用map存东西的时候用条件语句对其进行操作的时候,一定要考虑是否能够全部遍历到所有的数据中,并且考虑计数单位的用法。比如样例

4
0 0 0 0
1 2 3 4

如果把mx = -1代入则会wa test3

是因为根本没有遍历到整个map中

下面是ac代码

#include<bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define per(i, a, b) for(int i = a; i >= b; i --)
#define int long long
using namespace std;
typedef long long ll;
map<long double, int> mp;
const int maxn = 2e5 + 10;
long double a[maxn], b[maxn];

signed main(){
	int n;
	cin>>n;
	rep(i,1,n)cin>>a[i];
	rep(i,1,n)cin>>b[i];
	int normal = 0;
	rep(i,1,n)
	{
		if(a[i] == 0)
		{
			if(b[i] == 0)
			normal++;
		}
		else
		{
			mp[b[i]/a[i]]++;
		}
	 }
	 map<long double,int >::iterator it;
	 int mx = -1;
	 for(it = mp.begin();it!=mp.end();it++) 
	 {
	 	
	 //	cout<<it->second<<endl; 
	 	if(it->second>mx)
	 	{
	 		mx = it->second;
		 }
	 }
	 cout<<normal+mx<<endl;
	 
	
	return 0;
} 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值