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
题意:有个餐厅接待客人只有单人桌和双人桌,来的客人也是一个人或者两个人,如果来的就一个人就优先做单人桌,如果没有单人桌就坐空着的双人桌,如果这两个都没有就坐只坐一个人的双人桌,如果所有的情况都不满足就拒接这个客人。如果来的客人是两个人,就安排双人桌,如果没有就拒接。最后输出拒接客人的个数。
解题思路:知道题意就可以直接模拟了。具体看代码
#include <iostream>
using namespace std;
int main()
{
int n,one,two,two_one=0;
cin>>n>>one>>two;
int ans = 0,a;
for(int i=0;i<n;i++){
cin>>a;
if(a==1){//有一个客人
if(one>0)//看是否还有单人桌,如果有单人桌数目减一
one--;
else if(two>0){//否则看看有没有空着的双人桌,如果有,双人桌数目减一,留下半个双人桌。
two--;
two_one++;
}
else if(two_one>0)//最后看看还有没有半个的双人桌,如果有半个的双人桌数目减一
two_one--;
else//以上情况都不满足,拒接客人
ans++;
}
else{//有两个客人,如果有双人桌,双人桌数目减一,否则拒接
if(two>0)
two--;
else
ans+=2;
}
}
cout<<ans<<endl;
return 0;
}