D - Zero Quantity Maximization CodeForces - 1133D (map函数)

探讨了如何通过选择最优实数d,将两个整数数组通过特定公式转换为新数组c,以实现c中零元素数量的最大化。文章分享了一种使用map函数进行桶排序的方法,并提供了详细的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 ddoptimally.

Examples

Input

5
1 2 3 4 5
2 4 7 11 3

Output

2

Input

3
13 37 39
1 2 3

Output

2

Input

4
0 0 0 0
1 2 3 4

Output

0

Input

3
1 2 -1
-6 -12 6

Output

3

Note

In the first example, we may choose d=−2d=−2.

In the second example, we may choose d=−113d=−113.

In the third example, we cannot obtain any zero in array cc, no matter which dd we choose.

In the fourth example, we may choose d=6d=6.

题意:问满足ci:=d⋅ai+bici:=d⋅ai+bi.的d有是多少

题解:用map函数桶排

代码:


//Full of love and hope for life

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f
//https://paste.ubuntu.com/
//https://www.cnblogs.com/zzrturist/    //博客园
//https://blog.youkuaiyun.com/qq_44134712     //csdn

using namespace std;

typedef long long ll;
const ll N=1e5+10;
const int mod=1000000007;

int n;
map<long double,int>mp;
int num=0;
int ma=0;

signed main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    long double a[n], b[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
        if(a[i]==0){
            if(b[i]==0){
                num++;
            }
        }
        else{
            mp[b[i]/a[i]]++;
        }
    }
    map<long double,int>::iterator it;
    for(it=mp.begin(); it!=mp.end(); it++){
        if(it->second>ma){
            ma=it->second;
        }
    }
    cout << ma+num;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

ZZ --瑞 hopeACMer

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

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

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

打赏作者

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

抵扣说明:

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

余额充值