1 second
256 megabytes
standard input
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.
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.
Print the total number of people the restaurant denies service to.
4 1 2
1 2 1 1
0
4 1 1
1 1 2 1
2
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.
有一家店里面有两种桌子,a个一个坐的桌子和b个两人坐的桌子,他们的店会进来n个团体,n个团体里面都只有1人或2人。安排座位的顺序是这样的,从团体来的时间从前往后依次安排,比如第二组样例,有1个一个人坐的桌子和2个两个坐的桌子,那么先进来第一个人,安排到那一个桌子上,又进来1个人,安排在两个人的桌子上,又进来两个人,那么坐不下了,就请出去,又来一个人,坐在两个人桌子上剩余的那个位置。
#include <bits/stdc++.h> int n, a, b, k; int main(){
scanf("%d%d%d", &n, &a, &b);
int restb = b*;
int deny = ;
for(int i = ; i < n; i++){
scanf("%d", &k);
if(k == ){
if(a > ) a--;
else if((a == ) && b){
b--;
restb--;
}
else if(restb){
restb--;
}
else deny++;
}
else{
if(b){
b--;
restb-=;
}
else deny+=;
}
}
printf("%d\n", deny);
}
//使用额外变量half记录双人座的单个位子
#include <iostream>
using namespace std; int main() { int n,a,b,half=,value=;
cin>>n>>a>>b; for(int x=;x<n;x++)
{
int m;
cin>>m; if(m==)
{
if(a>)
{
a--;
}
else if(b>)
{
b--;
half++;
}
else if(half>)
{
half--;
}
else
value++;
}
else if(m==)
{
if(b>)
b--;
else
value+=;
}
}
cout<<value<<endl;
return ;
}