Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- using namespace std;
- int main()
- {
- int n, k;
- cin >> n >> k;
- string s;
- cin >> s;
- int c = 0;
- if (k < 0)
- {
- c = -k;
- k = 0;
- }
- for(int i = 0; i < n - 1; i++)
- {
- if (s[i] == 'A') k++;
- else if (s[i] == 'C')
- {
- k--;
- if (k < 0)
- {
- c++;
- k = 0;
- }
- }
- }
- cout << c;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement