Codeforces Round #544 (Div. 3) D. Zero Quantity Maximization

Codeforces Round #544 (Div. 3) 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 ?a and ?b, each contains ?n integers.

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

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

Input

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

The second line contains ?n integers ?1a1, ?2a2, ..., ??an (109??109−109≤ai≤109).

The third line contains ?n integers ?1b1, ?2b2, ..., ??bn (109??109−109≤bi≤109).

Output

Print one integer — the maximum number of zeroes in array ?c, if you choose ?d optimally.

Examples
input
Copy
5
1 2 3 4 5
2 4 7 11 3
output
Copy
2
input
Copy
3
13 37 39
1 2 3
output
Copy
2
input
Copy
4
0 0 0 0
1 2 3 4
output
Copy
0
input
Copy
3
1 2 -1
-6 -12 6
output
Copy
3
Note

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

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

In the third example, we cannot obtain any zero in array ?c, no matter which ?d we choose.

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

 

题目不难,更多的是关于心态的反思。

在比赛中遇到问题时,不应该慌乱,应该仔细再读一读题,在纸上把自己的思路写出来,检查有没有错误,不要想当然。

 

#include "bits/stdc++.h"

using namespace std;
const int maxn = 2e5 + 100;
typedef long long ll;

struct node {
    ll a, b;
};

bool operator<(node a, node b) {
    if (a.a != b.a) return a.a < b.a;
    return a.b < b.b;
}

map<node, ll> mp;

ll a[maxn], b[maxn];


int main() {
    //freopen("input.txt", "r", stdin);
    ll n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    ll gcd;
    node temp;
    ll tot = 0;
    for (int i = 1; i <= n; i++) {
        cin >> b[i];
        if (a[i] == 0 && b[i] != 0) {
            continue;
        } else if (a[i] != 0 && b[i] == 0) {
            temp.a = 0;
            temp.b = 0;
        } else if (a[i] == 0 && b[i] == 0) {
            tot++; //比赛时忽视了这种情况。。。
            continue;
        } else {
            gcd = __gcd(a[i], b[i]);
            a[i] /= gcd;
            b[i] /= gcd;
            if (a[i] < 0) {
                a[i] *= -1;
                b[i] *= -1;
            }
            temp.a = a[i];
            temp.b = b[i];
            //temp.a = min(a[i], b[i]);  //这样写会产生错误,比如a=3,b=4与a=4,b=3会归到一种情况,只需要在前面统一a[i]的符号就足够了
            //temp.b = max(a[i], b[i]);
        }
        mp[temp]++;
    }
    map<node, ll>::iterator it;
    it = mp.begin();
    ll ans = 0;
    while (it != mp.end()) {
        ans = max(ans, it->second);
        it++;
    }
    cout << ans + tot << endl;
    return 0;
}

 

posted @ 2019-03-08 14:41 Albert_liu 阅读( ...) 评论( ...) 编辑 收藏
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值