Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS_
  2.  
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <vector>
  6. #include <cmath>
  7. #include <string>
  8.  
  9. #define sz(a) int(a.size())
  10. #define all(a) a.begin(), a.end()
  11. #define fore(i, l, r) for(int i = int(l); i < int(r); i++)
  12. #define forn(i, n) fore(i, 0, n)
  13. #define pb push_back
  14. #define x first
  15. #define y second
  16.  
  17.  
  18. using namespace std;
  19.  
  20.  
  21.  
  22. int main() {
  23. ios_base::sync_with_stdio(0);
  24. cin.tie(0);
  25. //#ifdef _DEBUG
  26. freopen("input.txt", "r", stdin);
  27. freopen("output.txt", "w", stdout);
  28. //#endif
  29. int n,k;
  30. cin >> n >> k;
  31. vector <int> cnt(27);
  32. vector <int> a(n);
  33. forn(i,n) {
  34. cin >> a[i];
  35. }
  36. int kol = 0;
  37. int l = 0;
  38. int r = -1;
  39. forn(i,n) {
  40. if (kol == k) {
  41. break;
  42. }
  43. if (cnt[a[i]] == 0) {
  44. kol++;
  45. }
  46. cnt[a[i]]++;
  47. r = i + 1;
  48. }
  49. if (kol < k) {
  50. cout << n;
  51. return 0;
  52. }
  53. int ans = r - l;
  54. int cnt_ans = 1;
  55. while (r < n) {
  56. if (cnt[a[r]] == 0) {
  57. kol++;
  58. while (kol > k) {
  59. if (cnt[a[l]] == 1) {
  60. kol--;
  61. }
  62. cnt[a[l]]--;
  63. l++;
  64. }
  65. }
  66. cnt[a[r]]++;
  67. r++;
  68. if (r - l > ans) {
  69. ans = r - l;
  70. cnt_ans = 1;
  71. }
  72. else if (r - l == ans) {
  73. cnt_ans++;
  74. }
  75. }
  76. if (r - l > ans) {
  77. ans = r - l;
  78. cnt_ans = 1;
  79. }
  80. else if (r - l == ans) {
  81. cnt_ans++;
  82. }
  83. cout << ans << " " << cnt_ans;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement