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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include<bits/stdc++.h>
 
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define turbo ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vll vector<pll>
#define vii vector<pii>
#define vi vector<int>
#define vii vector<pii>
#define vl vector<ll>
#define vvi vector<vi>
#define vvii vector<vii>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vb>
#define vvvb vector<vvb>
#define mid (l+r)/2
#define endl '\n'
#define lowbit(x) x&(-x)
#define bits(x) __builtin_popcount(x) 
#define mins(se) (*se.begin())
#define maxs(se) (*--se.end())
#define ALL(x) x.begin(), x.end()
#define vs vector<string>

using namespace std;

const int N = 4020;

int n, k;

vii seg;

vi kr;
int res;

void check() {
    int il = seg.size();
    for(auto [a, b] : seg) 
        for(auto it : kr)
            if(a <= it and it < b) {
                il--;
                break;
            }
    res = min(res, il);
}

void jzd(int i = 1, int le = k-1) {
    if(!le) {
        check();
        return;
    }
    kr.pb(i);
    jzd(i+1, le-1);
    kr.popb();

    if(i+le == n)
        return;

    jzd(i+1, le);
}

int main() {
    turbo
    string s;
    cin >> n >> k >> s;
    s = "#" + s;

    for(int i = 1; i <= n; i++) {
        int bal = 0;
        for(int j = i; j <= n; j++) {
            bal += (s[j] == '(' ? 1 : -1);
            if(bal < 0)
                break;
            if(!bal)
                seg.pb({i, j});
        }
    }

    res = seg.size();
    jzd();
    cout << res;
}