Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <math.h>
  4. using namespace std;
  5.  
  6. int main() {
  7.     int numOfStudents, numOfStudents2;
  8.     std::unordered_map<int,int> firstGroup;
  9.     std::unordered_map<int,int> secondGroup;
  10.     std::cin >> numOfStudents;
  11.     numOfStudents2 = numOfStudents;
  12.     while(numOfStudents--)
  13.     {
  14.         int a;
  15.         std::cin >> a;
  16.         ++firstGroup[a];
  17.     }
  18.     while(numOfStudents2--)
  19.     {
  20.         int a;
  21.         std::cin >> a;
  22.         ++secondGroup[a];
  23.     }
  24.     int diff = 0;
  25.     for (int i = 1; i <= 5; ++i)
  26.     {
  27.         diff += std::abs(firstGroup[i] - secondGroup[i]);
  28.     }
  29.     if (diff % 4 != 0)
  30.         std::cout << -1 << std::endl;
  31.     else
  32.         std::cout << diff / 4 << std::endl;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement