There are 𝑛 consecutive seat places in a railway carriage. Each place is either empty or occupied by a passenger.
The university team for the Olympiad consists of 𝑎 student-programmers and 𝑏 student-athletes. Determine the largest number of students from all 𝑎+𝑏 students, which you can put in the railway carriage so that:
no student-programmer is sitting next to the student-programmer; and no student-athlete is sitting next to the student-athlete. In the other words, there should not be two consecutive (adjacent) places where two student-athletes or two student-programmers are sitting.
Consider that initially occupied seat places are occupied by jury members (who obviously are not students at all).
Input The first line contain three integers 𝑛, 𝑎 and 𝑏 (1≤𝑛≤2⋅105, 0≤𝑎,𝑏≤2⋅105, 𝑎+𝑏>0) — total number of seat places in the railway carriage, the number of student-programmers and the number of student-athletes.
The second line contains a string with length 𝑛, 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.
Output 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.
Examples inputCopy 5 1 1 … outputCopy 2 inputCopy 6 2 3 …. outputCopy 4 inputCopy 11 3 10 .…**.. outputCopy 7 inputCopy 3 2 3
outputCopy 0 Note In the first example you can put all student, for example, in the following way: .AB
In the second example you can put four students, for example, in the following way: BABB
In the third example you can put seven students, for example, in the following way: BABAB**AB
The letter A means a student-programmer, and the letter B — student-athlete.
模拟,不解释
#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include <set> #include <map> #include <queue> using namespace std; typedef long long ll; const int maxn = 3e5 + 7; char s[maxn]; int main() { int n,a,b;scanf("%d%d%d",&n,&a,&b); scanf("%s",s + 1); int ans = 0,pre = 0; for(int i = 1;i <= n;i++) { if(s[i] == '.') { if(pre == 0) { if(b && b >= a) { ans++; b--; pre = 2; } else if(a && a >= b) { ans++; a--; pre = 1; } } else if(pre == 1) { if(b) { b--; ans++; pre = 2; } else { pre = 2; } } else if(pre == 2) { if(a) { a--; ans++; pre = 1; } else { pre = 1; } } } else { pre = 0; } } printf("%d\n",ans); }