Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. ifstream fin ("livada.in");
  6.  
  7. ofstream fout ("livada.out");
  8.  
  9. int n, m, p, a[700005];
  10.  
  11. int Elmaj()
  12.  
  13. {
  14.  
  15. int cand, s;
  16.  
  17. cand = a[1];
  18. s = 1;
  19.  
  20. for(int i = 2 ; i <= m ; i++)
  21. {
  22.  
  23. if(cand != a[i])
  24.  
  25. s--;
  26.  
  27. else s++;
  28.  
  29. if(s == 0)
  30.  
  31. {
  32.  
  33. cand = a[i];
  34.  
  35. s = 1;
  36.  
  37. }
  38.  
  39. }
  40.  
  41. s = 0;
  42.  
  43. for(int i = 1 ; i <= m ; i++)
  44.  
  45. if(a[i] == cand)
  46. s++;
  47.  
  48. if(s > m / 2)
  49.  
  50. return 1;
  51.  
  52. return 0;
  53.  
  54. }
  55.  
  56. int Secv_Elem_Cons()
  57.  
  58. {
  59.  
  60. int s, lgmax;
  61.  
  62. s = lgmax = 1;
  63. for(int i = 2 ; i <= m ; i++)
  64.  
  65. {
  66.  
  67. if(a[i] == a[i - 1])
  68.  
  69. s++;
  70.  
  71. else
  72. s = 1;
  73.  
  74. lgmax = max(lgmax, s);
  75.  
  76. }
  77.  
  78. return lgmax;
  79.  
  80. }
  81.  
  82. int main()
  83.  
  84. {
  85.  
  86. int lgmax,nr = 0;
  87.  
  88. fin >> n >> m >> p;
  89. lgmax = 0;
  90. for(int i = 1 ; i <= n ; i++)
  91. {
  92.  
  93. for(int j = 1 ; j <= m ; j++)
  94.  
  95. fin >> a[j];
  96. if(Elmaj())
  97.  
  98. nr++;
  99.  
  100. lgmax = max(lgmax, Secv_Elem_Cons());
  101.  
  102. }
  103.  
  104. fout << nr << "\n" << lgmax << "\n";
  105.  
  106.  
  107.  
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement