• Round #423 A.Restaurant Tables(Div.2)


    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·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.

     1 #include <iostream>
     2 #include <stdio.h>
     3 using namespace std;
     4 int dan,shuang,can;
     5 int main(){
     6     int n,ans,sum=0;
     7     cin>>n>>dan>>shuang;
     8     for(int i=0;i<n;i++){o
     9         scanf("%d",&ans);
    10         if(ans==1){
    11             if(dan>0) dan--;
    12             else if(shuang>0) {
    13                 shuang--;
    14                 can++;
    15             }
    16             else if(can>0) can--;
    17             else sum+=1;
    18         }
    19         else {
    20             if(shuang>0) shuang--;
    21             else sum+=2;
    22         }
    23     }
    24     cout<<sum<<endl;
    25     return 0;
    26 }
  • 相关阅读:
    27. 移除元素
    axios调用webapi报错
    MySql重装以后,修改数据库路径,打开以前的数据库报Table 'XX库.XX表' doesn't exist错误的解决办法
    SqlServer2012,设置指定数据库对指定用户开放权限
    win10无法访问服务器上的共享文件夹怎么设置,提示:你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问
    Vs2017的git的坑
    jira6.3.6创建问题不自动发邮件通知的问题
    在windows下面配置redis集群遇到的一些坑
    SqlServer2008 无法修改表,超时时间已到 在操作完成之前超时解决方法
    小程序中也可以使用三元运算符且可嵌套使用
  • 原文地址:https://www.cnblogs.com/z-712/p/7307869.html
Copyright © 2020-2023  润新知