-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path676C.cpp
More file actions
64 lines (47 loc) · 1.09 KB
/
676C.cpp
File metadata and controls
64 lines (47 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
using namespace std;
void init_code() {
ios::sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
ll chars, changes;
string str;
ll getMaxLenght(char target) {
ll longest = 0, left = 0, changed = 0;
for (ll right = 0; right < chars; right++) {
if (str[right] != target) {
changed++;
}
while (changed > changes) {
if (str[left] != target) {
changed--;
}
left++;
}
longest = max(longest, right - left + 1);
}
return longest;
}
void solve() {
cin >> chars >> changes >> str;
ll maxA = getMaxLenght('a');
ll maxB = getMaxLenght('b');
cout << max(maxA, maxB);
}
int main() {
init_code();
solve();
return 0;
}
/*
i can start by finding the longest equal subsequence of As or Bs
i have to change chars on a subsequence to find a larger one
but also have to keep track of how many times i changed
but how do i keep track of where i did the changes when sliding the window?
*/