962B.md (2216B)
1 Source: https://codeforces.com/problemset/problem/962/B 2 3 B. Students in Railway Carriage 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 There are $n$ consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger. 22 23 The university team for the Olympiad consists of $a$ student-programmers and $b$ student-athletes. Determine the largest number of students from all $a+b$ students, which you can put in the railway carriage so that: 24 25 * no student-programmer is sitting next to the student-programmer; 26 * and no student-athlete is sitting next to the student-athlete. 27 28 In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting. 29 30 Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all). 31 32 Input 33 34 The first line contain three integers $n$, $a$ and $b$ ($1 \le n \le 2\cdot10^{5}$, $0 \le a, b \le 2\cdot10^{5}$, $a + b \gt 0$) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes. 35 36 The second line contains a string with length $n$, consisting of characters "." and "*". The dot means that the corresponding place is empty. The asterisk means that the corresponding place is occupied by the jury member. 37 38 Output 39 40 Print the largest number of students, which you can put in the railway carriage so that no student-programmer is sitting next to a student-programmer and no student-athlete is sitting next to a student-athlete. 41 42 Examples 43 44 Input 45 46 ``` 47 5 1 1 48 *...* 49 ``` 50 51 Output 52 53 ``` 54 2 55 ``` 56 57 Input 58 59 ``` 60 6 2 3 61 *...*. 62 ``` 63 64 Output 65 66 ``` 67 4 68 ``` 69 70 Input 71 72 ``` 73 11 3 10 74 .*....**.*. 75 ``` 76 77 Output 78 79 ``` 80 7 81 ``` 82 83 Input 84 85 ``` 86 3 2 3 87 *** 88 ``` 89 90 Output 91 92 ``` 93 0 94 ``` 95 96 Note 97 98 In the first example you can put all student, for example, in the following way: *.AB* 99 100 In the second example you can put four students, for example, in the following way: *BAB*B 101 102 In the third example you can put seven students, for example, in the following way: B*ABAB**A*B 103 104 The letter A means a student-programmer, and the letter B — student-athlete.