#ifndef INCLUDED_MAIN #define INCLUDED_MAIN #include __FILE__ int main(){ int n,k; string s; cin>>n>>k>>s; vector st; vector match(n,-1); rep(i,n){ if(s[i]=='(') st.push_back(i); else{ int j=st.back(); st.pop_back(); match[i]=j; match[j]=i; } } int root=0; st.clear(); vector id(n,-1); int tid=0; rep(i,n) if(s[i]=='(') id[i]=tid++; vector p(tid,-1); rep(i,n){ if(s[i]=='(') st.push_back(i); else{ int op=match[i]; int cid=id[op]; st.pop_back(); if(!st.empty()){ int pop=st.back(); int pid=id[pop]; p[cid]=pid; } else root=cid; } } vector> children(tid); rep(i,tid) if(p[i]>=0) children[p[i]].push_back(i); vector fmin(tid,0), x(tid,0); function dfs=[&](int u){ ll sumc=0; for(int v:children[u]){ if(!dfs(v)) return false; sumc+=fmin[v]; } int sc=(int)children[u].size(); ll minn=(sc>=2?0:2-sc); fmin[u]=sumc+minn; x[u]=minn; return true; }; if(!dfs(root)||fmin[root]>k){ no(); return 0; } x[root]+=k-fmin[root]; function build=[&](int u){ vector items; for(int v:children[u]) items.push_back(build(v)); for(int i=0;i using namespace std; #define rep(i,n) for(ll i=0;i #define vc vector ll calc_min(const string &s){ stack st; for(char c:s){ if(c=='('){ st.push(0); } else { ll cur=st.top(); st.pop(); ll sc=(cur==0 ? 2 : cur+1); if(st.empty()) st.push(sc); else{ ll t=st.top(); st.pop(); st.push(t+sc); } } } return st.empty()?0:st.top(); } bool taio(const string &s){ ll bal=0; for(char c:s){ if(c=='(') bal++; else{ if(bal==0) return false; bal--; } } return bal==0; } template bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} void no() { cout<<"No"<& a) { ll ans=0; for(auto i:a) ans+=i; return ans; } #endif