forked from isanchez-aguilar/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1133D - Zero Quantity Maximization.cpp
70 lines (55 loc) · 1.14 KB
/
1133D - Zero Quantity Maximization.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* User: Isanchez_Aguilar
* Problem: CodeForces 1133D - Zero Quantity Maximization
*/
#include <bits/stdc++.h>
using namespace std;
using Long = int;
using Fraction = pair<Long, Long>;
inline Fraction reduceFraction(const Fraction& f)
{
Fraction reduction = f;
if (reduction.first < 0)
{
reduction.first *= -1;
reduction.second *= -1;
}
else if(reduction.first == 0 and reduction.second < 0)
reduction.second *= -1;
Long gcd = __gcd(abs(reduction.first), abs(reduction.second));
reduction.first /= gcd;
reduction.second /= gcd;
return reduction;
}
int main(void)
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<Long> a(n);
vector<Long> b(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
for (int i = 0; i < n; ++i)
cin >> b[i];
int ans = 0;
int maxFreq = 0;
map<Fraction, int> freq;
for (int i = 0; i < n; ++i)
{
if (a[i] == 0)
{
if (b[i] == 0)
++ans;
}
else
{
Fraction d = reduceFraction(Fraction(-b[i], a[i]));
++freq[d];
maxFreq = max(maxFreq, freq[d]);
}
}
cout << ans + maxFreq << "\n";
return 0;
}