题目地址:http://codeforces.com/contest/828/problem/A
题意:你有一家餐厅,有单人桌和双人桌,给你一串序列,告诉你来的人的个数和顺序,你要按他的条件来安排座位,问你有多少人被拒绝用餐。
一个人来的位置的优先级
1° 有单人桌
2° 有双人桌
3° 有单人坐的双人座
4° 离开
两个人来的位置的优先级
1° 有双人桌
2° 离开
思路:直接模拟
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define LL long long
#define N 200100
#define M 50010
#define inf 0x3f3f3f3f
using namespace std;
const LL mod = 1e9 + 7;
const double eps = 1e-9;
int num;
int main() {
cin.sync_with_stdio(false);
int n, a, b, c, sum;
while (cin >> n >> a >> b) {
c = 0;
sum = 0;
for (int i = 0; i < n; i++) {
cin >> num;
if (num == 1) {
if (a > 0) {
a--;
}
else if (b > 0) {
b--;
c++;
}
else if (c > 0) {
c--;
}
else {
sum++;
}
}
else {
if (b > 0) {
b--;
}
else {
sum+=2;
}
}
}
cout << sum << endl;
}
return 0;
}