a53

PlatouK_V2

a53
Mar 13th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. /// Solutie - Moca Andrei - 100p
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int n, k, maxi, a[10001][103], l, x, y, smax = -1, elem = -1, s, cerinta;
  5. void proces(int nr)
  6. {
  7. int aux = a[nr][a[nr][0]];
  8. int j = a[nr][0]-1;
  9. while (aux > a[nr][j] && j)
  10. a[nr][j+1] = a[nr][j], j--;
  11. a[nr][j+1] = aux;
  12. while (a[nr][0] > k)
  13. a[nr][0]--;
  14. }
  15. int main()
  16. {
  17. cin >> k >> n >> x;
  18. maxi = x;
  19. for (int i = 2; i <= n; i++)
  20. {
  21. cin >> y;
  22. maxi = max(maxi, y);
  23. if (x == y)
  24. l++;
  25. else
  26. {
  27. a[x][0]++;
  28. a[x][a[x][0]] = l;
  29. proces(x);
  30. l = 1;
  31. }
  32. x = y;
  33. }
  34. a[x][0]++;
  35. a[x][a[x][0]] = l;
  36. proces(x);
  37. for (int i = 0; i <= maxi; i++)
  38. {
  39. s = 0;
  40. for (int j = 1; j <= a[i][0]; j++)
  41. s += a[i][j];
  42. if (s >= smax)
  43. smax = s, elem = i;
  44. }
  45. cin >> cerinta;
  46. if (cerinta == 1)
  47. cout << smax;
  48. else
  49. cout << elem;
  50. return 0;
  51. }
Add Comment
Please, Sign In to add comment