#P10317. Ensure Victory in Clash Royale Deck Construction
Ensure Victory in Clash Royale Deck Construction
Ensure Victory in Clash Royale Deck Construction
Player A loves playing Clash Royale. In Clash Royale there are three types of cards: troops, buildings, and spells. A deck consists of exactly 8 cards. A valid deck must satisfy the following composition rules:
- Building cards: 0 or 1 card.
- Spell cards: between 1 and 3 cards (inclusive).
- Troop cards: no restrictions (fill the rest of the deck).
Each card has an independent level \(a_i\) and type \(c_i\). Player A has \(n\) cards available (with known level and type). Player B will use a deck whose 8 card levels are all known. Player A is very confident in his ability; he can guarantee a win if the average level of his deck is at least the opponent's average level minus 2. In mathematical terms, if
[ \frac{\text{sum of A's deck levels}}{8} \ge \frac{\text{sum of B's deck levels}}{8} - 2, ]
or equivalently, if
[ \text{sum of A's deck levels} \ge \text{sum of B's deck levels} - 16, ]
and if the deck is valid with respect to the composition rules above, then Player A can ensure victory.
Your task is to determine if Player A can build a valid deck from his available cards to guarantee a win.
inputFormat
The input is given as follows:
- The first line contains an integer \(n\) \( (8 \le n \le 10^5)\), the number of cards Player A has.
- Each of the next \(n\) lines contains an integer \(a_i\) and a string \(c_i\), representing the level and the type of the \(i\)th card. The type is one of
troop
,building
, orspell
. - The last line contains 8 integers, representing the levels of the 8 cards that Player B will use.
You can assume that there is at least one valid deck if the composition rules can be met.
outputFormat
Output a single line: YES
if Player A can build a valid deck that guarantees a win; otherwise, output NO
.
sample
10
10 troop
8 troop
7 spell
6 troop
10 spell
9 troop
5 building
8 troop
7 troop
10 troop
8 8 8 8 8 8 8 8
YES