Students in Railway Carriage

链接:http://codeforces.com/problemset/problem/962/B

B. Students in Railway Carriage

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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.

Examples

Input

Copy

5 1 1
*...*

Output

Copy

2

Input

Copy

6 2 3
*...*.

Output

Copy

4

Input

Copy

11 3 10
.*....**.*.

Output

Copy

7

Input

Copy

3 2 3
***

Output

Copy

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.

题意:就是说这里有一些座位以及一些学生,学生又分为普通学生与学生运动员,简称stu1,stu2吧。然后给出的座位中有的是空的,有的是有人的,题目要求你输出这些座位中能坐的最大学生数,(stu1不能喝stu1坐在一起,stu2和stu2不能坐在一起)。

思路:直接暴力,刚开始设一个flag,判断stu1和stu2值的大小,stu1大则flag为1,否则flag为0;然后遍历整个字符串、如果这一点是 点则代表这里是空的,可以坐人。然后对flag值和stu1,stu2的值进行判定,

如果flag为1且stu1>0,则stu1-=1.

如果flag为0且stu2>0,则stu2-=1;

每次判断后另flag=!flag;更新flag值

如果该点是星号 ,则判断stu1和stu2值的大小,stu1大则flag为1,否则flag为0;

直到遍历完整个字符串。

最后用原来的学生总数减去现在的学生总数,就是要求的答案。

#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<stack>
#include<stdlib.h>
#include<map>
#include<vector>
#define MAX 200002
#define INF 0x3f3f3f3f
using namespace std;
int flag;
int n,stu1,stu2;
string seat;
int a[40001];
int main()
{
    cin>>n>>stu1>>stu2;
    int zz=stu1+stu2;
    cin>>seat;
    if(stu1>stu2)
        flag=1;
    else
        flag=0;
    for(int i=0; i<n; i++)
    {
        if(seat[i]=='.')
        {
            if(flag&&stu1)
            {
                stu1--;
            }
            else if(!flag&&stu2)
            {
                stu2--;
            }
            flag=!flag;
        }
        else
        {
            if(stu1>stu2)
                flag=1;
            else
                flag=0;
        }
    } printf("%d\n",zz-stu1-stu2);
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值