### Pronlem A

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 21 2 1 1`
output
`0`
input
`4 1 11 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.

注意读题，客人先愿意坐空桌子(当然单个客人会先选择单人桌)！题目跳着跳着看，然后吃大亏了。。。

### Code

``` /**
* Codeforces
* Problem#828A
* Accepted
* Time:15ms
* Memory:2056k
*/
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <stack>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std;
typedef bool boolean;
const signed int inf = (signed)((1u << ) - );
const signed long long llf = (signed long long)((1ull << ) - );
const double eps = 1e-;
const int binary_limit = ;
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
}

int n, a, b, c = ;
int cnt = ;

inline void init() {
}

inline void solve() {
for(int i = , x; i <= n; i++) {
if(x == ) {
if(a)
a--;
else if(b)
c += , b -= ;
else if(c)
c--;
else
cnt++;
} else {
if(!b)
cnt += ;
else
b--;
}
//        cout << a << " " << b << endl;
}
printf("%d\n", cnt);
}

int main() {
init();
solve();
return ;
}```

Problem A

Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.

You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.

The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.

Output

Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.

Examples
input
`5 4WWWWWWWBWWWBWWBBWWWW`
output
`5`
input
`1 2BB`
output
`-1`
input
`3 3WWWWWWWWW`
output
`1`
Note

In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).

In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.

In the third example all cells are colored white, so it's sufficient to color any cell black.

找出最大的纵坐标之差和横坐标之差，然后判一下边界就很轻松了。

### Code

``` /**
* Codeforces
* Problem#828B
* Accepted
* Time:15ms
* Memory:2100k
*/
#include <iostream>
#include <cstdio>
#include <ctime>
#include <cmath>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>
#include <stack>
#ifndef WIN32
#define Auto "%lld"
#else
#define Auto "%I64d"
#endif
using namespace std;
typedef bool boolean;
const signed int inf = (signed)((1u << ) - );
const signed long long llf = (signed long long)((1ull << ) - );
const double eps = 1e-;
const int binary_limit = ;
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
template<typename T>
char x;
int aFlag = ;
while(!isdigit((x = getchar())) && x != '-' && x != -);
if(x == -) {
ungetc(x, stdin);
return false;
}
if(x == '-'){
x = getchar();
aFlag = -;
}
for(u = x - ''; isdigit((x = getchar())); u = (u << ) + (u << ) + x - '');
ungetc(x, stdin);
u *= aFlag;
return true;
}

int n, m;
char mmap[][];
int maxx = , minx = inf, maxy = , miny = inf;
int cnt = ;

inline void init() {
gets(mmap[]);
for(int i = ; i <= n; i++) {
gets(mmap[i] + );
for(int j = ; j <= m; j++) {
if(mmap[i][j] == 'W')    continue;
smax(maxx, i);
smax(maxy, j);
smin(minx, i);
smin(miny, j);
cnt++;
}
}
}

inline void solve() {
if(minx == inf) {
puts("");
return;
}
int maxlen = max(maxx - minx, maxy - miny);
if(maxlen >= m || maxlen >= n) {
puts("-1");
} else {
printf("%d\n", (maxlen + ) * (maxlen + ) - cnt);
}
}

int main() {
init();
solve();
return ;
}```

## Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem A - B的更多相关文章

1. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem E (Codeforces 828E) - 分块

Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A ...

2. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 828D) - 贪心

Arkady needs your help again! This time he decided to build his own high-speed Internet exchange poi ...

3. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) Problem C (Codeforces 828C) - 链表 - 并查集

Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun ...

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

Codeforces Round #423 (Div. 1, rated, based on VK Cup Finals) A.String Reconstruction B. High Load C ...

5. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) E. DNA Evolution 树状数组

E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that D ...

6. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) D. High Load 构造

7. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 并查集

C. String Reconstruction 题目连接: http://codeforces.com/contest/828/problem/C Description Ivan had stri ...

8. Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) A,B,C

A.题目链接:http://codeforces.com/contest/828/problem/A 解题思路: 直接暴力模拟 #include<bits/stdc++.h> using ...

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

## 随机推荐

1. C#编程模式之扩展命令

C#编程模式之扩展命令 前言 根据上一篇的命令模式和在工作中遇到的一些实际情况,有了本篇文章,时时都是学习的一个过程,会在这个过程中发现许多好的模式或者是一种开发方式,今天写出来的就是我工作中常用到的 ...

2. Selenium 元素定位

selenium通过driver.findElement(By selector)来定位元素,selector在selenium-java.jar中,里面的方法一共就8种,如下图: 基本定义: By. ...

3. AttributeError: type object &#39;_io.StringIO&#39; has no attribute &#39;StringIO&#39;

python2导入StringIO模块,直接: from StringIO import StringIO 对于python3,StringIO和cStringIO模块已经没了,如果要使用的话,需要导 ...

5. Ubuntu SSH 客户端的应用 | sshfs映射远程文件系统为本地磁盘

SSH是指Secure Shell,是一种安全的传输协议. Ubuntu客户端通过SSH访问远程服务器 ,以下步骤是客户端 的配置方法: 1. sudo apt-get install ssh 2. ...

6. .NET 实现Base-64加密解密处理

.NET 实现Base-64加密解密处理 using System; using System.Collections.Generic; using System.Linq; using System ...

7. Python之excel文件追加内容

首先要安装三个模块:xlrd,xlwt,xlutils 命令:pip install xlrd xlwt xlutils 示例代码: #!/usr/bin/env python # -*- codin ...

8. 0x16 Tire