forked from anandadfoxx/codeforces_solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
349A.cpp
34 lines (31 loc) · 805 Bytes
/
349A.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <bits/stdc++.h>
#define FOR(i, start, end) for(int i = start; i < end; i++)
using namespace std;
typedef long long LL;
int main() {
int n;
cin >> n;
int chg25 = 0, chg50 = 0;
bool able = true;
FOR(i, 0, n) {
int val;
cin >> val;
if (val == 25) chg25++;
else if (val == 50) {
if (chg25 < 1) able = false;
else chg25--;
chg50++;
}
else if (val == 100) {
if (!(chg25 >= 3 || (chg25 >= 1 && chg50 >= 1))) able = false;
else {
if (chg50 >= 1 && chg25 >= 1) {
chg50--;
chg25--;
}
else if (chg25 >= 3) chg25 -= 3;
}
}
}
printf((able) ? "YES\n" : "NO\n");
}