Codeforces #423-Div. 2—A. Restaurant Tables

3 篇文章 0 订阅

题目:A. Restaurant Tables

time limit per test1 second
memory limit per test256 megabytes

描述:

In a small restaurant there are a tables for one person and b tables for two persons.

It it known that n groups of people come today, each consisting of one or two people.

If a group consist of one person, it is seated at a vacant one-seater table. If there are none of them, it is seated at a vacant two-seater table. If there are none of them, it is seated at a two-seater table occupied by single person. If there are still none of them, the restaurant denies service to this group.

If a group consist of two people, it is seated at a vacant two-seater table. If there are none of them, the restaurant denies service to this group.

You are given a chronological order of groups coming. You are to determine the total number of people the restaurant denies service to.

Input

The first line contains three integers n, a and b (1 ≤ n ≤ 2·105, 1 ≤ a, b ≤ 2·105) — the number of groups coming to the restaurant, the number of one-seater and the number of two-seater tables.

The second line contains a sequence of integers t1, t2, …, tn (1 ≤ ti ≤ 2) — the description of clients in chronological order. If ti is equal to one, then the i-th group consists of one person, otherwise the i-th group consists of two people.

Output

Print the total number of people the restaurant denies service to.

Examples

input
4 1 2
1 2 1 1
output
0
input
4 1 1
1 1 2 1
output
2

Note

In the first example the first group consists of one person, it is seated at a vacant one-seater table. The next group occupies a whole two-seater table. The third group consists of one person, it occupies one place at the remaining two-seater table. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, all clients are served.

In the second example the first group consists of one person, it is seated at the vacant one-seater table. The next group consists of one person, it occupies one place at the two-seater table. It’s impossible to seat the next group of two people, so the restaurant denies service to them. The fourth group consists of one person, he is seated at the remaining seat at the two-seater table. Thus, the restaurant denies service to 2 clients.

题意:

题目就是说一个餐厅有n波人来就餐,其中餐厅有a个单人座,b个双人座,如果来的人数是单数,优先坐单人座,如果没有了坐没人的双人座,如果还没有就坐有一个人的双人座,再没有就无法招待。如果来的人数是两人,若没有全空的双人座则无法招待(两人无法拆分),最后求无法招待的人数。

思路:

知道意思了就是水题了,记录下来当前的座位情况,如果可以招待更新座位情况,不可以招待则记录数量,最后输出就好。

代码:

#include <bits/stdc++.h>

using namespace std;
int dan,shuang,can;
int main()
{
    int n,ans,sum=0;
    cin>>n>>dan>>shuang;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&ans);
        if(ans==1)
        {
            if(dan>0) dan--;
            else if(shuang>0)
            {
                shuang--;
                can++;
            }
            else if(can>0) can--;
            else sum+=1;
        }
        else
        {
            if(shuang>0) shuang--;
            else sum+=2;
        }
    }
    cout<<sum<<endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值