Codeforces Round #423 A Restaurant Tables(模拟)

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

 

有一家店里面有两种桌子,a个一个坐的桌子和b个两人坐的桌子,他们的店会进来n个团体,n个团体里面都只有1人或2人。安排座位的顺序是这样的,从团体来的时间从前往后依次安排,比如第二组样例,有1个一个人坐的桌子和2个两个坐的桌子,那么先进来第一个人,安排到那一个桌子上,又进来1个人,安排在两个人的桌子上,又进来两个人,那么坐不下了,就请出去,又来一个人,坐在两个人桌子上剩余的那个位置。

 1 #include <bits/stdc++.h>
 2 
 3 int n, a, b, k;
 4 
 5 int main(){
 6     scanf("%d%d%d", &n, &a, &b);
 7     int restb = b*2;
 8     int deny = 0;
 9     for(int i = 0; i < n; i++){
10         scanf("%d", &k);
11         if(k == 1){
12             if(a > 0) a--;
13             else if((a == 0) && b){
14                 b--;
15                 restb--;
16             }
17             else if(restb){
18                 restb--;
19             }
20             else deny++;
21         }
22         else{
23             if(b){
24                 b--;
25                 restb-=2;
26             }
27             else deny+=2;
28         }
29     }
30     printf("%d
", deny);
31 }
 1 //使用额外变量half记录双人座的单个位子
 2 #include <iostream>
 3 using namespace std;
 4 
 5 int main() {
 6     
 7     int n,a,b,half=0,value=0;
 8     cin>>n>>a>>b;
 9     
10     for(int x=0;x<n;x++)
11     {
12         int m;
13         cin>>m;
14         
15         if(m==1)
16         {
17             if(a>0)
18             {
19                 a--;
20             }
21             else if(b>0)
22             {
23                 b--;
24                 half++;
25             }
26             else if(half>0)
27             {
28                 half--;
29             }
30             else
31             value++;
32         }
33         else if(m==2)
34         {
35             if(b>0)
36             b--;
37             else 
38             value+=2;
39         }
40     }
41     cout<<value<<endl;
42     return 0;
43 }

 

原文地址:https://www.cnblogs.com/Roni-i/p/7154119.html