302144: CF408B. Garland

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Garland

题意翻译

【题目描述】 有一次,Vasya在一本杂志上读到一篇文章,内容是如何用彩纸制作美丽的手工花环。Vasya立即到店里买了N张彩纸,每张纸的面积为1平方米。 花环必须由任意面积的彩纸组成,每件纸片有确定的颜色。为了制作花环,Vasya可以任意地把他现有的彩纸剪成纸片。Vasya不必用所有的纸片来制作花环。 Vasya希望花环尽可能吸引人,因此他希望用来制作花环的M张纸的总面积尽可能大。请你计算出Vasya的花环中纸片的最大总面积。 【输入输出格式】 输入格式 第一行是一个包含N(1<=N<=1000)个连续的小写英文字母("a"…"z")的序列。(没有空格)每个字母表示Vasya有一张对应颜色的纸。 第二行是一个包含M(1<=M<=1000)连续的小写英文字母的序列,表示Vasya想要制作的花环中纸片的颜色。 输出格式: 输出一个整数,这个整数是Vasya想要得到的花环上的纸片的最大的可能总面积。如果他手上的彩纸不能得到他希望的花环的话,输出-1。保证答案永远是整数。 【说明】 在第一个测试样例中,Vasya可以制作一个面积为6的花环:他可以使用两张彩色B,三张(但不是四张)彩色A,并将一张彩色C切成三张(比如说剪成相等的三块)。Vasya可以利用所得的碎片制作出面积为6的花环。 在第二个测试样例中,Vasya根本不能做花环——他没有一张彩色的Z。

题目描述

Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought $ n $ colored sheets of paper, the area of each sheet is 1 square meter. The garland must consist of exactly $ m $ pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland. Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​ $ m $ pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.

输入输出格式

输入格式


The first line contains a non-empty sequence of $ n $ ( $ 1<=n<=1000 $ ) small English letters ("a" $ ... $ "z"). Each letter means that Vasya has a sheet of paper of the corresponding color. The second line contains a non-empty sequence of $ m $ ( $ 1<=m<=1000 $ ) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.

输出格式


Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.

输入输出样例

输入样例 #1

aaabbac
aabbccac

输出样例 #1

6

输入样例 #2

a
z

输出样例 #2

-1

说明

In the first test sample Vasya can make an garland of area 6: he can use both sheets of color $ b $ , three (but not four) sheets of color $ a $ and cut a single sheet of color $ c $ in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6. In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color $ z $ .

Input

题意翻译

【题目描述】 有一次,Vasya在一本杂志上读到一篇文章,内容是如何用彩纸制作美丽的手工花环。Vasya立即到店里买了N张彩纸,每张纸的面积为1平方米。 花环必须由任意面积的彩纸组成,每件纸片有确定的颜色。为了制作花环,Vasya可以任意地把他现有的彩纸剪成纸片。Vasya不必用所有的纸片来制作花环。 Vasya希望花环尽可能吸引人,因此他希望用来制作花环的M张纸的总面积尽可能大。请你计算出Vasya的花环中纸片的最大总面积。 【输入输出格式】 输入格式 第一行是一个包含N(1<=N<=1000)个连续的小写英文字母("a"…"z")的序列。(没有空格)每个字母表示Vasya有一张对应颜色的纸。 第二行是一个包含M(1<=M<=1000)连续的小写英文字母的序列,表示Vasya想要制作的花环中纸片的颜色。 输出格式: 输出一个整数,这个整数是Vasya想要得到的花环上的纸片的最大的可能总面积。如果他手上的彩纸不能得到他希望的花环的话,输出-1。保证答案永远是整数。 【说明】 在第一个测试样例中,Vasya可以制作一个面积为6的花环:他可以使用两张彩色B,三张(但不是四张)彩色A,并将一张彩色C切成三张(比如说剪成相等的三块)。Vasya可以利用所得的碎片制作出面积为6的花环。 在第二个测试样例中,Vasya根本不能做花环——他没有一张彩色的Z。

加入题单

算法标签: