博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
CodeForces 12C Fruits
阅读量:6899 次
发布时间:2019-06-27

本文共 2749 字,大约阅读时间需要 9 分钟。

Fruits
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Submit     

Description

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).

Input

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.

Output

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.

Sample Input

Input
5 3 4 2 1 10 5 apple orange mango
Output
7 19
Input
6 5 3 5 1 6 8 1 peach grapefruit banana orange orange
Output
11 30
1 #include 
2 #include
3 #include
4 using namespace std; 5 6 int main() 7 { 8 int n,m; 9 int i,j,k;10 int price[105],namss[105];11 char nam[105][36];12 while(scanf("%d %d",&n,&m)!=EOF)13 {14 memset(namss,0,sizeof(namss));15 for(i=1;i<=n;i++)16 scanf("%d",&price[i]);17 sort(price+1,price+n+1);18 for(i=1;i<=m;i++)19 {20 k=0;21 scanf("%s",&nam[i]);22 for(j=1;j
=1;i--)45 {46 ans1=ans1+namss[i]*price[m-i+1];47 ans2=ans2+namss[i]*price[n-m+i];48 }49 printf("%d %d\n",ans1,ans2);50 }51 return 0;52 }
View Code

 

转载于:https://www.cnblogs.com/cyd308/p/4771500.html

你可能感兴趣的文章
元素水平居中和垂直居中的几种方式
查看>>
爬虫学习日记(八)
查看>>
撩课-Web大前端每天5道面试题-Day33
查看>>
快捷键方式
查看>>
使用pug模板中的问题
查看>>
Shell基础之运算符 & 环境变量配置文件
查看>>
乖乖兽:是什么让你减肥会反弹?这3点很多人都没注意
查看>>
变量作用域和作用域链
查看>>
MAC下安装配置Tomcat
查看>>
GMQ钱包APP全方位保证数字货币资产安全
查看>>
Android 开发面经,历时两月斩获BAT+头条四个公司 Offer
查看>>
Logstash/Elasticsearch/Kibana安装
查看>>
命令别名:保护和服务
查看>>
Ubuntu 常用软件推荐(QQ、微信、MATLAB等)及安装过程
查看>>
Gradle 使用技巧(二) - SO/NDK过滤
查看>>
Java核心技术笔记 对象与类
查看>>
创建本地git仓库
查看>>
css实现开关switch插件
查看>>
Android O 后台startService限制浅析
查看>>
【vue-page-stack】Vue页面堆栈管理器
查看>>