Codeforces828 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 <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <bitset> using namespace std; #define LL long long
const int INF = 0x3f3f3f3f;
#define MAXN 500
int main()
{
int n,a,b,c,x;
scanf("%d%d%d",&n,&a,&b);
c=0;
int ans=0;
int tot=0;
for(int i=0; i<n; i++)
{
scanf("%d",&x);
tot+=x;
if(x==1)
{
if(a>0)
a--,ans+=1;
else if(b>0)
b--,c++,ans+=1;
else if( c>0)
c--,ans++;
}
else if(x==2)
{
if(b>0)
b--,ans+=2;
}
}
printf("%d",tot-ans);
return 0;
}
Codeforces828 A. Restaurant Tables的更多相关文章
- Codeforces Round #423 A Restaurant Tables(模拟)
A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard ...
- cf 828 A. Restaurant Tables
A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard ...
- 【Codeforces Round #423 (Div. 2) A】Restaurant Tables
[Link]:http://codeforces.com/contest/828/problem/A [Description] 有n个组按照时间顺序来餐馆; 每个组由一个人或两个人组成; 每当有一个 ...
- http://codeforces.com/contest/828
哇这是我打的第一场cf,第一题都wa了无数次,然后第二题差几分钟交 ,第二天一交就AC了内心是崩溃的.果然我还是太菜l.... A. Restaurant Tables time limit per ...
- Codeforces Round #423 (Div. 2)
codeforces 423 A. Restaurant Tables [水题] //注意,一个人选座位的顺序,先去单人桌,没有则去空的双人桌,再没有则去有一个人坐着的双人桌.读清题意. #inclu ...
- 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 ...
- Flo's Restaurant[HDU1103]
Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1103 Flo's Restaurant(模拟+优先队列)
Flo's Restaurant Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【模拟】Flo's Restaurant
[poj2424]Flo's Restaurant Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2960 Accept ...
随机推荐
- Spring Bean生命周期详解
对象生命周期:创建(实例化----初始化)---使用----销毁,而在Spring中,Bean对象周期当然遵从这一过程,但是Spring提供了许多对外接口,允许开发者对三个过程(实例化.初始化.销毁) ...
- delete content on the right of cursor, Mac
delete content on the right of cursor, Mac It's not convenient to press Fn+delete to delete content ...
- VS2015+Opencv3.2配置(一次配好)
对于 VS2015+QT5.8的配置我就不介绍了,由于我配置的比较早,具体有的东西忘掉了,大家可以参考下面这几篇文章. 留白留白留白留白留白(稍后补) 对于Opencv+VS的配置是我重点要说的内容. ...
- python学习笔记_week28
heap import heapq import random heap = [] data = list(range(10000)) random.shuffle(data) # for num i ...
- python中TCP粘包问题解决方案
TCP协议中的粘包问题 1.粘包现象 基于TCP写一个远程cmd功能 #服务端 import socket import subprocess sever = socket.socket() seve ...
- dto vo
不过符合规矩的做法是DTO里可以放各种List<VO>,而VO和entity就是一一对应的关系,vo里不能放entity,entity里也不能放vo,vo和entity只存放和数据库完全相 ...
- SVG绘制太极图
思路:先画一整个圆,填充颜色为黑色,再用一个边框和填充颜色均为白色的长方形覆盖右半边的半圆,再以同一个圆心,相同半径绘制一整个圆,该圆的边线颜色为黑色,没有填充颜色,最后常规操作再画四个小圆 源代码: ...
- mysql_day03
MySQL-Day02回顾1.表记录的管理 1.删除表记录 1.delete from 表名 where 条件; ## 不加where条件全部删除 2.更新表记录 1.update 表名 set 字段 ...
- IP路由配置之---------dhcp服务器配置
实验设备:一台华三路由器,一台PC 步骤一,在系统视图下打开dhcp功能,禁用IP(网关,域名服务器) [H3C]dhcp enable # [H3C]dhcp server forbidden-ip ...
- 762. Prime Number of Set Bits in Binary Representation二进制中有质数个1的数量
[抄题]: Given two integers L and R, find the count of numbers in the range [L, R] (inclusive) having a ...