28 lines
521 B
C++
28 lines
521 B
C++
#include <iostream>
|
|
#include <set>
|
|
#include <cmath>
|
|
|
|
int main()
|
|
{
|
|
std::multiset<int> as{};
|
|
std::multiset<int> bs{};
|
|
int a{};
|
|
int b{};
|
|
while (std::cin >> a >> b)
|
|
{
|
|
as.insert(a);
|
|
bs.insert(b);
|
|
}
|
|
|
|
int distance{};
|
|
int similarity{};
|
|
|
|
for (auto ia = as.cbegin(), ib = bs.cbegin(); ia != as.end(); ++ia, ++ib)
|
|
{
|
|
distance += std::abs(*ia - *ib);
|
|
similarity += *ia * bs.count(*ia);
|
|
}
|
|
std::cout << "Total difference: " << distance << "\n";
|
|
std::cout << "Total distance: " << similarity << "\n";
|
|
return 0;
|
|
} |