CF12C.Fruits
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times.
When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags).
春天来了,这意味着柜台上有许多水果。一个阳光明媚的日子,小男孩瓦列拉决定去购物。他列出了自己想买的 m 种水果。如果瓦列拉想购买某种水果多于一个,他就会在清单中多次列出该水果。
当他来到阿绍特的水果摊时,他发现卖家尚未将价格标签贴到商品上,而是把所有价格标签都放在了柜台上。之后,阿绍特会将每个价格标签贴到某一种水果上,这样瓦列拉就能计算出他清单上所有水果的总价。但瓦列拉现在就想知道:在对价格标签进行最“幸运”(即对他最有利)的分配方式下,总价可能的最小值是多少;以及在最“不幸”(即对他最不利)的分配方式下,总价可能的最大值是多少。
输入格式
The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.
输入的第一行包含两个整数 n 和 m(1 ≤ n, m ≤ 100)—— 分别表示价格标签的数量(即 Ashot 所售水果种类数)和 Valera 购物清单中的物品数量。
第二行包含 n 个用空格分隔的正整数,每个数均不超过 100,表示某种水果的单价。
接下来的 m 行每行包含购物清单中的一种水果名称。每个名称均为非空字符串,仅由小写拉丁字母组成,长度不超过 32。
保证购物清单中不同水果的种类数不超过 n。此外,已知卖家库存充足,能够满足 Valera 所需购买的所有水果。
输出格式
Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.
输出两个数 a 和 b(满足 a≤b)——瓦莱拉购买清单上所有水果所需花费的最小值和最大值。
输入输出样例
输入#1
5 3 4 2 1 10 5 apple orange mango
输出#1
7 19
输入#2
6 5 3 5 1 6 8 1 peach grapefruit banana orange orange
输出#2
11 30
输入解题思路,AI测评打分。不知道怎么写?