a53

PlatouK

a53
Jul 28th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. /// Solutie - Moca Andrei - 100p
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5. int a[10002][102], n, x, c = 1, y, s, smax, k, l[10002], nr, cerinta;
  6. bool cmp(int a1, int a2)
  7. {
  8. if (a1 > a2)
  9. return 1;
  10. return 0;
  11. }
  12. int main()
  13. {
  14. cin >> k >> n >> x;
  15. int imin = x, imax = x;
  16. for (int i = 2; i <= n; i++)
  17. {
  18. cin >> y;
  19. imin = min(imin, y);
  20. imax = max(imax, y);
  21. if (x == y)
  22. c++;
  23. if (x != y || i == n)
  24. {
  25. l[x]++;
  26. a[x][l[x]] = c;
  27. sort (a[x] + 1, a[x] + l[x] + 1, cmp);
  28. if (l[x] > k)
  29. a[x][l[x]] = 0, l[x] = k;
  30. c = 1;
  31. }
  32. x = y;
  33. }
  34. cin >> cerinta;
  35. for (int i = imin; i <= imax; i++)
  36. {
  37. for (int j = 1; j <= k; j++)
  38. s += a[i][j];
  39. if (s > smax)
  40. smax = s, nr = i;
  41. else
  42. if (s == smax)
  43. nr = i;
  44. s = 0;
  45. }
  46. if (cerinta == 1)
  47. cout << smax;
  48. else
  49. if (cerinta == 2)
  50. cout << nr;
  51. return 0;
  52. }
Add Comment
Please, Sign In to add comment