/* -*- 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 cmppii(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); qpii q0, q1; vpii es; 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({j, i}); else q1.push({j, i}); } else if (lf || rf) q1.push({j, i}); else es.push_back({j, i}); } while (m > 0 && ! q0.empty()) { auto [l, r] = q0.front(); q0.pop(); for (int i = l + 1; m > 0 && i < r; i += 2) s[i] = 'o', m--; } while (m > 0 && ! q1.empty()) { auto [l, r] = q1.front(); q1.pop(); 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--; } sort(es.begin(), es.end(), cmppii); for (auto [l, r]: es) { if (m <= 0) break; if (r - l >= 3) for (int i = l; i < r; i += 2) s[i] = 'o', 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; }