A9420 | Garland
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 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.
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$ .
In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color $z$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted