There are nn 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 aa student-programmers and bb student-athletes. Determine the largest number of students from all a+ba+b 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 nn, aa and bb (1≤n≤2⋅1051≤n≤2⋅105, 0≤a,b≤2⋅1050≤a,b≤2⋅105, a+b>0a+b>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 nn, 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.ExamplesinputCopy
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: *BAB*B
In the third example you can put seven students, for example, in the following way: B*ABAB**A*B
The letter A means a student-programmer, and the letter B — student-athlete.
思路:贪心+模拟。当前能放人的时候看前面是否#,不是就放当前剩下人多的。
如果.的前面是有人了,就放另一种人。
或者前面是.,说明有一种人用完了,放另外一种人就好了。
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<algorithm>
using namespace std;
const int maxn=2e5+100;
typedef long long LL;
LL num[maxn];
//strlen()函数是O(n)的复杂度
int main(void)
{
LL n,a,b;cin>>n>>a>>b;
char str[maxn];
cin>>str;
LL len=strlen(str);
LL cnt=0;
if(a==0&&b==0)
{
cout<<cnt<<endl;return 0;
}
for(LL i=0;i<len;i++)
{
if(a==0&&b==0) break;
if(str[i]=='.')
{
if(i==0||str[i-1]=='*'||str[i-1]=='.')//如果有一个放完了,另一个没放完,就是前面还是.的情况
{
if(a>=b)
{
str[i]='A';
a-=1;
cnt++;
// cout<<"cnt="<<cnt<<endl;
}
else
{
str[i]='B';
b-=1;
cnt++;
// cout<<"cnt="<<cnt<<endl;
}
}
else
{
if(str[i-1]=='A'&&b)
{
b--,cnt++,str[i]='B';
// cout<<"cnt="<<cnt<<endl;
}
else if(str[i-1]=='B'&&a)
{
a--,cnt++,str[i]='A';
// cout<<"cnt="<<cnt<<endl;
}
}
}
}
cout<<cnt<<endl;
return 0;
}