fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int n, f[10]={0}, fa[10]={0}, fb[10]={0} ;
  7.  
  8. void process(){
  9. int res = 0;
  10. for (int i = 1; i <= 5; i++){
  11. res += abs(fa[i]-f[i]);
  12. }
  13. cout << res/2;
  14. }
  15.  
  16. int main(){
  17. cin >> n;
  18. int t;
  19. for (int i = 1; i <= n; i++){
  20. cin >> t;
  21. f[t]++;
  22. fa[t]++;
  23. }
  24. for (int i = 1; i <= n; i++){
  25. cin >> t;
  26. f[t]++;
  27. fb[t]++;
  28. }
  29. for (int i = 1; i <= 5; i++){
  30. if (f[i]%2==1){
  31. cout << -1;
  32. return 0;
  33. }
  34. }
  35. for (int i = 1; i <= 5; i++){
  36. f[i]/=2;
  37. }
  38. process();
  39. return 0;
  40. }
Success #stdin #stdout 0s 16064KB
stdin
4
5 4 4 4
5 5 4 5
stdout
1