KarleFKremen

Untitled

May 25th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define FILE ""
  6. #define FILEIO 0
  7. #define LONG 0
  8. #define IOSOPT 1
  9.  
  10. #if LONG
  11. typedef long long ll;
  12. typedef unsigned long long ull;
  13. #else // LONG
  14. typedef int ll;
  15. typedef unsigned int ull;
  16. #endif
  17. typedef short sym;
  18. #define pb push_back
  19. #define mp make_pair
  20. #define p(a, b) pair < a, b >
  21. #define rev(a) reverse(a.begin(), a.end())
  22. #define ord(a) sort(a.begin(), a.end())
  23. #define rm erase
  24. #define rs resize
  25. #define sz size
  26. #define fi first
  27. #define se second
  28. #define ins insert
  29. #define die(a) \
  30. { \
  31. cout << a << endl; \
  32. exit(0); \
  33. }
  34. #define stlprint(a) \
  35. for(auto _STL_ITER = a.begin(); _STL_ITER != a.end(); _STL_ITER++) \
  36. { \
  37. cout << (*_STL_ITER) << ' '; \
  38. }
  39.  
  40. p(ll, ll) p[100500];
  41. char tmp[100500];
  42.  
  43. main()
  44. {
  45. #if IOSOPT
  46. ios_base::sync_with_stdio(0);
  47. cin.tie(0);
  48. #endif // IOSOPT
  49. #if FILEIO
  50. freopen(FILE".in", "r", stdin);
  51. freopen(FILE".out", "w", stdout);
  52. #endif
  53. ll n, k;
  54. string a;
  55. scanf("%d %d", &n, &k);
  56. scanf("%s", tmp);
  57. a = tmp;
  58. for(int i = 1; i <= a.sz(); i++)
  59. {
  60. p[i] = p[i - 1];
  61. (a[i - 1] == 'a' ? p[i].fi : p[i].se)++;
  62. }
  63. ll l = 1, r = 1, res = -1;
  64. while(r <= n)
  65. {
  66. if (r < l) l = r;
  67. if((p[r].fi - p[l - 1].fi) <= k)
  68. res = max(res, (r++) - l + 1);
  69. else
  70. l++;
  71. }
  72. l = r = 1;
  73. while(r <= n)
  74. {
  75. if (r < l) l = r;
  76. if((p[r].se - p[l - 1].se) <= k)
  77. res = max(res, (r++) - l + 1);
  78. else
  79. l++;
  80. }
  81. l = r = 1;
  82. printf("%d", res);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment