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