codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1023C.md (1574B)


      1 Source: https://codeforces.com/problemset/problem/1023/C
      2 
      3 C. Bracket Subsequence
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.
     22 
     23 Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
     24 
     25 You are given a regular bracket sequence $s$ and an integer number $k$. Your task is to find a regular bracket sequence of length exactly $k$ such that it is also a subsequence of $s$.
     26 
     27 It is guaranteed that such sequence always exists.
     28 
     29 Input
     30 
     31 The first line contains two integers $n$ and $k$ ($2 \le k \le n \le 2 \cdot 10^5$, both $n$ and $k$ are even) — the length of $s$ and the length of the sequence you are asked to find.
     32 
     33 The second line is a string $s$ — regular bracket sequence of length $n$.
     34 
     35 Output
     36 
     37 Print a single string — a regular bracket sequence of length exactly $k$ such that it is also a subsequence of $s$.
     38 
     39 It is guaranteed that such sequence always exists.
     40 
     41 Examples
     42 
     43 Input
     44 
     45 ```
     46 6 4  
     47 ()(())
     48 ```
     49 
     50 Output
     51 
     52 ```
     53 ()()
     54 ```
     55 
     56 Input
     57 
     58 ```
     59 8 8  
     60 (()(()))
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 (()(()))
     67 ```