arc103_a - Avav
28 Jan 2021 — Tags: None
Click to show code.
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
template <typename InputIterator,
typename T = typename iterator_traits<InputIterator>::value_type>
void read_n(InputIterator it, int n)
{
copy_n(istream_iterator<T>(cin), n, it);
}
template <typename InputIterator,
typename T = typename iterator_traits<InputIterator>::value_type>
void write(InputIterator first, InputIterator last, const char *delim = "\n")
{
copy(first, last, ostream_iterator<T>(cout, delim));
}
int const NMAX = 1e5 + 11;
int main(void)
{
ios::sync_with_stdio(false), cin.tie(NULL);
int n;
cin >> n;
vi f0(NMAX, 0), f1(NMAX, 0), f2(NMAX, 0);
for (int i = 0; i < n; ++i)
{
int ai;
cin >> ai;
if (i % 2 == 0)
++f0[ai];
else
++f1[ai];
++f2[ai];
}
sort(f0.begin(), f0.end(), greater<int>());
sort(f1.begin(), f1.end(), greater<int>());
sort(f2.begin(), f2.end(), greater<int>());
f0;
if (f2[0] == f0[0] + f1[0])
cout << n - max(f0[0] + f1[1], f0[1] + f1[0]) << endl;
else
cout << n - f0[0] - f1[0] << endl;
return 0;
}