Canadian Computing Competition: 2004 Stage 2, Day 1, Problem 1
Nixed, he placed the flong into the calathi halfway through the yuga.
Huh?
Believe it or not, the above sentence is actually a valid English sentence. It also has two other features: it looks like spam, and the words are very valuable.
Valuable, you say? (For some reason, you are doing lots of talking to yourself today).
Yes, valuable, if you are playing Scribble. In the standard game of Scribble, calathi
(which means "a vase-shaped basket represented in Greek painting and sculpture") is worth
Specifically, as you may know, each letter in Scribble is worth a given number of points. The goal is to get the most points with a given set of letters.
For this question, we will modify the game slightly. Suppose you have
Input Specification
You are given a number a 7 2
means you have two tiles marked a
and each is worth
Output Specification
The output is one line long, containing one integer, which is the maximum score. That is, the maximum number of points that can be attained by using the tiles to form one complete word. If no word can be formed, the maximum number of points is zero.
Sample Input
4
a 1 1
b 4 1
c 2 1
d 10 4
3
ab
bc
c
Sample Output
6
Comments