Skip to content

Instantly share code, notes, and snippets.

@MohamedTaha98
Last active July 24, 2017 21:43
Show Gist options
  • Save MohamedTaha98/b15198cf98f95d7e95fa5c595719f5e0 to your computer and use it in GitHub Desktop.
Save MohamedTaha98/b15198cf98f95d7e95fa5c595719f5e0 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
long n, a, b, c = 0, unserved = 0;
cin >> n >> a >> b;
long group[n];
for (int i = 0; i < n; i++) {
cin >> group[i];
if (group[i] == 1) {
if (a > 0)
a--;
else if (b > 0 && c == 0) {
c++;
b--;
}
else if (c > 0)
c--;
else
unserved += 1;
}
else if (group[i] == 2) {
if (b == 0)
unserved += 2;
else
b--;
}
}
cout << unserved;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment