CardsAndSlots
TCCC07 Semi 1 · 2007-07-30 · by andrewzta
Problem Statement
You have n cards. Each card has some integer value, and some letter written on it. You also have n slots in a row. Each slot has some required value.
You must place the cards in the slots such that each slot contains a card with a value greater than or equal to the required value of that slot. You must order the cards such that the string formed by reading the letters on the cards from left to right comes as early as possible lexicographically while not violating the first rule.
You are given a
Constraints
- values will contain between 1 and 50 elements, inclusive.
- Each element of values will be between 1 and 1000, inclusive.
- letters will contain exactly n characters, where n is the number of elements in values.
- letters will contain only uppercase letters ('A'-'Z').
- required will contain the same number of elements as values.
- Each element of required will be between 1 and 1000, inclusive.
{1, 2, 3}
"ABC"
{2, 2, 1}
Returns: "BCA"
{1, 2, 3, 4, 5}
"BBBAA"
{1, 1, 1, 1, 5}
Returns: "ABBBA"
Note that there can be equal letters on different cards.
{1, 1}
"AA"
{2, 2}
Returns: ""
No card fits any slot.
{91}
"R"
{26}
Returns: "R"
{110,519}
"RG"
{209,58}
Returns: "GR"
Submissions are judged against all 96 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CardsAndSlots with a public method string firstValid(vector<int> values, string letters, vector<int> required) · 96 test cases · 2 s / 256 MB per case