Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define FILE ""
- #define FILEIO 0
- #define LONG 0
- #define IOSOPT 1
- #if LONG
- typedef long long ll;
- typedef unsigned long long ull;
- #else // LONG
- typedef int ll;
- typedef unsigned int ull;
- #endif
- typedef short sym;
- #define pb push_back
- #define mp make_pair
- #define p(a, b) pair < a, b >
- #define rev(a) reverse(a.begin(), a.end())
- #define ord(a) sort(a.begin(), a.end())
- #define rm erase
- #define rs resize
- #define sz size
- #define fi first
- #define se second
- #define ins insert
- #define die(a) \
- { \
- cout << a << endl; \
- exit(0); \
- }
- #define stlprint(a) \
- for(auto _STL_ITER = a.begin(); _STL_ITER != a.end(); _STL_ITER++) \
- { \
- cout << (*_STL_ITER) << ' '; \
- }
- p(ll, ll) p[100500];
- char tmp[100500];
- main()
- {
- #if IOSOPT
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- #endif // IOSOPT
- #if FILEIO
- freopen(FILE".in", "r", stdin);
- freopen(FILE".out", "w", stdout);
- #endif
- ll n, k;
- string a;
- scanf("%d %d", &n, &k);
- scanf("%s", tmp);
- a = tmp;
- for(int i = 1; i <= a.sz(); i++)
- {
- p[i] = p[i - 1];
- (a[i - 1] == 'a' ? p[i].fi : p[i].se)++;
- }
- ll l = 1, r = 1, res = -1;
- while(r <= n)
- {
- if (r < l) l = r;
- if((p[r].fi - p[l - 1].fi) <= k)
- res = max(res, (r++) - l + 1);
- else
- l++;
- }
- l = r = 1;
- while(r <= n)
- {
- if (r < l) l = r;
- if((p[r].se - p[l - 1].se) <= k)
- res = max(res, (r++) - l + 1);
- else
- l++;
- }
- l = r = 1;
- printf("%d", res);
- }
Advertisement
Add Comment
Please, Sign In to add comment