Restaurant Tables

题目链接http://codeforces.com/problemset/problem/828/A

A. Restaurant Tables
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 na and b (1 ≤ n ≤ 2·1051 ≤ 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
题目大意:

一个饭馆内有两种餐桌:单人桌和双人桌。如果来1个客人,就坐单人桌,如果没有单人桌,就坐双人桌(这个双人桌可以已有一个人坐),如果连双人桌也没有,就拒绝接待该客人。如果同时来2个客人,就坐双人桌,如果没有双人桌,就是不能接待这两位客人。问在两种餐桌数量和当天顾客数量一定的情况下,当天拒绝多少位客人。

解题思路:

就是考察逻辑思维的,不断使用if  else 组合。需要注意的是:如果来了一位客人,则优先坐单人桌(也就是如果没有单人桌的情况下,才选择和  只有一位客人的双人桌  拼桌)。其它的都是考察逻辑思维的,认真思考就能做出来。

代码:(不提倡看本人的代码,因为比较乱,理解题意后自己写)

#include<iostream>
using namespace std;
int main()
{
    int n,a,b,w[200005],z,len,s2,sum,zz;
    while(cin>>n>>a>>b)
    {
        zz=0;
        s2=0;
        sum=0;
        len=n;
        for(int i=0;i<=len-1;i++)
            cin>>w[i];
        for(int i=0;i<=len-1;i++)
        {
            if(w[i]==1)
            {
                if(a>0)
                {
                    a--;
                    n--;
                }
                else
                {
                    if(b>0)
                    {
                        b--;
                        s2++;
                        n--;
                    }
                    else
                    {
                        if(s2>0)
                        {
                            s2--;
                            n--;
                        }
                        else
                        {
                            z=i;
                            break;
                        }
                    }
                }
            }
            else
            {
                if(b>0)
                {
                    b--;
                    n=n-2;
                }
                else
                    sum=sum+2;
            }
        }
        if(zz==1)
            continue;
        if(z!=0)
        {
            for(int i=z;i<=len-1;i++)
                sum=sum+w[i];
        }
        cout<<sum<<endl;
    }
    return 0;
}



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值