codeforces-1023 C Bracket Subsequence
1 #include <iostream> 2 #include <unordered_map> 3 #include <algorithm> 4 #include <vector> 5 #include <queue> 6 7 using namespace std; 8 9 int main() 10 { 11 int n,k; 12 while(cin >> n >> k) 13 { 14 string input; 15 cin >> input; 16 string result; 17 int right_existed = 0; 18 int left = 0; 19 int right = 0; 20 for(int i = 0; i < n; i ++) 21 { 22 if(right_existed!=k/2) 23 { 24 result += input[i]; 25 if(input[i]=='(') 26 { 27 right_existed ++; 28 left ++; 29 } 30 else 31 right ++; 32 } 33 } 34 int tmp = left - right; 35 while(tmp--) 36 result += ')'; 37 cout << result << endl; 38 } 39 return 0; 40 }