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 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
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>
#include <cstdio>
#include <cstring>
#include <queue>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
#define lowbit(x) x&(-x)
#define max(x,y) (x>y?x:y)
#define min(x,y) (x<y?x:y)
#define mem(a) (memset(a,0,sizeof(a)))
const int inf=0x3f3f3f3f;
int n,a,b,x;
int main()
{
int ans=;
int c=;
cin>>n>>a>>b;
for(int i=;i<n;i++)
{
scanf("%d",&x);
if(x==)
{
if(a!=) a--;
else if(b!=) c++,b--;
else if(c) c--;
else if(a== && b==) ans++;
}
else
{
if(b!=) b--;
else ans+=;
}
}
printf("%d\n",ans);
return ;
}

cf 828 A. Restaurant Tables的更多相关文章

  1. Codeforces828 A. Restaurant Tables

    A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #423 A Restaurant Tables(模拟)

    A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. 【Codeforces Round #423 (Div. 2) A】Restaurant Tables

    [Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...

  4. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)

    题目链接:http://codeforces.com/contest/828 A. Restaurant Tables time limit per test 1 second memory limi ...

  5. http://codeforces.com/contest/828

    哇这是我打的第一场cf,第一题都wa了无数次,然后第二题差几分钟交 ,第二天一交就AC了内心是崩溃的.果然我还是太菜l.... A. Restaurant Tables time limit per ...

  6. Codeforces Round #423 (Div. 2)

    codeforces 423 A. Restaurant Tables [水题] //注意,一个人选座位的顺序,先去单人桌,没有则去空的双人桌,再没有则去有一个人坐着的双人桌.读清题意. #inclu ...

  7. cf 261B.Maxim and Restaurant

    什么什么期望的,不会! (题解http://blog.sina.com.cn/s/blog_140e100580102wj4e.html(看不懂)) #include<bits/stdc++.h ...

  8. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  9. [转]Responsive Tables Demo

    本文转自:http://elvery.net/demo/responsive-tables/ A quick and dirty look at some techniques for designi ...

随机推荐

  1. mysql5.7 安装方法 (跟旧的不一样了)

    MySQL 5.7发布之后很多网友都在说,打开想安装文件夹.但是文件夹中没有DATA目录, 没有mysqly默认库.启动不了数据库,那是因为5.7的数据库的初始化方法和之前的初始化不一样了. 首先这里 ...

  2. deque迭代器失效的困惑?

    在实现LRU算法的时候lru_list 開始用的是deque 可是由于害怕其在插入删除上的迭代器失效情况的诡异情况.遂用list取代之. 在数据量比較大的时候性能不是非常好.性能优化分析的时候决定用d ...

  3. STM32中assert_param的使用

    在STM32的固件库和提供的例程中.到处都能够见到assert_param()的使用. 假设打开不论什么一个例程中的stm32f10x_conf.h文件,就能够看到实际上assert_param是一个 ...

  4. OC中的@的作用研究

    OC中的@字符用的频率很的高,其主要作用是为了差别于其它语言的keyword和语法 以下我们来研究一下其应用 1.声明类,协议,延展,权限,属性等 @interface声明类 @protocol声明协 ...

  5. [ACM] hdu 4248 A Famous Stone Collector (DP+组合)

    A Famous Stone Collector Problem Description Mr. B loves to play with colorful stones. There are n c ...

  6. c++命名规范与代码风格

    http://blog.sina.com.cn/s/blog_a3a8d0b1010100uw.html http://www.cnblogs.com/len3d/archive/2008/02/01 ...

  7. 51nod-1322: 关于树的函数

    [传送门:51nod-1322] 简要题意: 给出n个点的两棵无根树,编号都是从0到n-1 现在每棵树任意选出一条边割断,设第一棵树选出的边为e1,第二棵树选出的边为e2 很显然割断后两棵树各分成了四 ...

  8. bzoj1801: [Ahoi2009]chess 中国象棋(DP)

    1801: [Ahoi2009]chess 中国象棋 题目:传送门 题解: 表示自己的DP菜的抠脚 %题解... 定义f[i][j][k]表示前i行 仅有一个棋子的有j列 有两个棋子的有k个 的方案数 ...

  9. 一站式学习WireShark

    一 基础 http://blog.sina.com.cn/s/blog_987e00020102x5k1.html 选中一个数据包,右键选中某一个数据包,然后follow-->Tcp Strea ...

  10. pandas入门10分钟——serries其实就是data frame的一列数据

    10 Minutes to pandas This is a short introduction to pandas, geared mainly for new users. You can se ...