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 ;
}

最新文章

  1. java 线程 Thread 使用介绍,包含wait(),notifyAll() 等函数使用介绍
  2. 安装phonegap3.2
  3. Emit学习(4) - Dapper解析之数据对象映射(二)
  4. Windows7、8无法访问其他计算机共享盘
  5. linux下logrotate 配置和理解
  6. 20. javacript高级程序设计-JSON
  7. 修复eclipse中使用mave update project后JRE都变成1.5的问题
  8. .SQL Server中 image类型数据的比较
  9. java的nio之:浅析I/O模型
  10. 添加iPhone设备的udid之后,重新生成开发证书(Development)
  11. 含有特殊字符的JSON串解析方法
  12. 制作win7+ubuntu +winPE+CDlinux多系统启动U盘
  13. ETL-Career RoadMap
  14. poi HSSFRichTextString 对cell中的每一段文字设置字体
  15. 解决xshell连接不上Ubuntu
  16. 【转】浅谈UML的概念和模型之UML九种图
  17. C# Lambda表达式和linq表达式 之 匿名对象查询接收
  18. Linux批量结束、杀死进程
  19. python note 4
  20. scrapy 框架入门

热门文章

  1. 对jvm进行gc的时间、数量、jvm停顿时间的监控
  2. Android Studio打包.so文件教程
  3. hadoop-14-进行libtirpc的rpm包安装
  4. select多选 multiple的使用
  5. 冒泡,简单选择,直接插入排序(Java版)
  6. C&amp;C控制服务的设计和侦测方法综述——DDoS攻击,上传从宿主机偷窃的到的信息,定时给感染机文件加密勒索等。
  7. Linux-php安装mongodb
  8. 35.自己实现vector模板库myvector
  9. SQL流程控制语句
  10. C#派生类中使用基类protected成员的方法