Advertisement
Infiniti_Inter

Untitled

Nov 13th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #include <cstdio>
  4. #include <vector>
  5. #include <cmath>
  6. #include <queue>
  7. #include <string>
  8. #include <cstring>
  9. #include <cassert>
  10. #include <iomanip>
  11. #include <algorithm>
  12. #include <set>
  13. #include <map>
  14. #include <ctime>
  15. #include <cmath>
  16.  
  17. #define f0(i,n) for (int i = 0; i < int(n); i++)
  18. #define fs first
  19. #define sc second
  20. #define sz(v) int(v.size())
  21. #define pb push_back
  22. #define mp make_pair
  23. #define y1 ________y1
  24.  
  25. template<typename X> inline X abs(const X& a) { return a < 0? -a: a; }
  26. template<typename X> inline X sqr(const X& a) { return a * a; }
  27.  
  28. typedef long long li;
  29. typedef long double ld;
  30.  
  31.  
  32. using namespace std;
  33. int a[5000 + 13] = {0};
  34. int b[5000 + 13];
  35. int c[5000 + 13]= {0};
  36. bool fl;
  37. int main()
  38. {
  39.  
  40. int n;
  41. cin >> n;
  42. int tmp;
  43. f0(i,n)
  44. {
  45. cin >> a[i] >> b[i];
  46. if (a[i] != b[i])
  47. {
  48. ++c[a[i]];
  49. ++c[b[i]];
  50. }
  51. if (a[i] == b[i])
  52. {
  53. ++c[a[i]];
  54. }
  55. tmp = max(tmp,max(a[i],b[i]));
  56. }
  57.  
  58. int max1 = 0, max2 = 0;
  59. f0(i,tmp)
  60. {
  61. if (c[i] >= max1)
  62. {
  63. max2 = max1;
  64. max1 = c[i];
  65. continue;
  66. }
  67. if (c[i] > max2) max2 = max1;
  68. }
  69. int Max = max1 + max2;
  70. int ans = n * 2 - Max;
  71. cout << ans << endl;
  72. return 0;
  73. //system("pause");
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement