/* -*- coding: utf-8 -*- * * 2553.cc: No.2553 Holidays - yukicoder */ #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 100000; /* typedef */ using pii = pair; using vpii = vector; using qpii = queue; /* global variables */ char s[MAX_N + 4]; /* subroutines */ bool ltpii(const pii &a, const pii &b) { return a.second - a.first < b.second - b.first; } bool gtpii(const pii &a, const pii &b) { return a.second - a.first > b.second - b.first; } /* main */ int main() { int n, m; scanf("%d%d%s", &n, &m, s); vpii q0, q1, q2; for (int i = 0; i < n;) { while (i < n && s[i] != '-') i++; if (i >= n) break; int j= i; while (i < n && s[i] == '-') i++; bool lf = (j > 0 && s[j - 1] == 'o'); bool rf = (i < n && s[i] == 'o'); if (lf && rf) { if ((i - j) & 1) q0.push_back({j, i}); else q1.push_back({j, i}); } else if (lf || rf) q1.push_back({j, i}); else q2.push_back({j, i}); } sort(q0.begin(), q0.end(), ltpii); for (auto [l, r]: q0) { if (m <= 0) break; for (int i = l + 1; m > 0 && i < r; i += 2) s[i] = 'o', m--; } //printf(" s=%s, m=%d\n", s, m); for (auto [l, r]: q1) { if (m <= 0) break; if (l > 0 && s[l - 1] == 'o') for (int i = l + 1; m > 0 && i < r; i += 2) s[i] = 'o', m--; else for (int i = r - 2; m > 0 && i >= l; i -= 2) s[i] = 'o', m--; } //printf(" s=%s, m=%d\n", s, m); sort(q2.begin(), q2.end(), gtpii); for (auto [l, r]: q2) { if (m <= 0) break; if (r - l >= 3) for (int i = l; m > 0 && i < r; i += 2) s[i] = 'o', m--; } //printf(" s=%s, m=%d\n", s, m); for (int i = 1; i + 1 < n; i++) if (s[i] == '-' && s[i - 1] == 'o' && s[i + 1] == 'o') s[i] = 'o'; for (int i = 0; m > 0 && i < n; i++) if (s[i] == '-') s[i] = 'o', m--; int cnt = 0; for (int i = 0; i < n; i++) if (s[i] == 'o') cnt++; printf("%d\n", cnt); return 0; }