CUC-SUMMER-7-A

A - Restaurant Tables
CodeForces - 828A

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.

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


題意:一個飯店有一人桌和兩人桌,對于單人來客如果有空的一人桌就安排到一人桌,沒有則安排到空的兩人桌,還沒有就安排到已經有一個人的兩人桌,否則就不招待了;對于兩人來客只安排到雙人桌,沒有則不招待,問最多能招待多少人。

解法:分別對單人桌、雙人桌、有一個人坐的雙人桌計數,直接模擬即可,注意顧客是有順序的。

代碼:

#include<iostream>
using namespace std;
int main()
{
    int n,a,b,ans=0,c,d=0;
    cin>>n>>a>>b;
    for(int i=0;i<n;i++){
        cin>>c;
        if(c==1){
            if(a>0)
                a--;
            else if(b>0){
                b--;
                d++;
            }
            else if(d>0)
                d--;
            else
                ans++;
        }
        else{
            if(b>0)
                b--;
            else
                ans+=2;
        }
    }
    cout<<ans<<endl;
    return 0;
}
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容

  • **2014真題Directions:Read the following text. Choose the be...
    又是夜半驚坐起閱讀 9,932評論 0 23
  • 感賞我親愛兒子,咳嗽夜里睡不好,今天還一大早起床背著那么重書包上學,晚上八九點才回家,真的是太辛苦了,孩子,媽媽的...
    吳若閱讀 137評論 0 0
  • 京城逍遙客閱讀 359評論 12 6
  • 未來的你,我想和你說聲對不起。 留給你的我是不完美的,沒有童年的稚嫩,沒有年少時的輕狂,沒有了那青春的放縱。沒有了...
    落下萬般塵閱讀 277評論 0 0
  • 我常常把世界上的人分為兩種,一種是知道自己有病的人,一種是不知道自己有病的人。對于第一種,我敬佩至極。他們具有良好...
    李研書柜閱讀 510評論 0 0