Fruits

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

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
 #include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; int main()
{
int n,m;
int i,j,k;
int price[],namss[];
char nam[][];
while(scanf("%d %d",&n,&m)!=EOF)
{
memset(namss,,sizeof(namss));
for(i=;i<=n;i++)
scanf("%d",&price[i]);
sort(price+,price+n+);
for(i=;i<=m;i++)
{
k=;
scanf("%s",&nam[i]);
for(j=;j<i;j++)
{
if(strcmp(nam[i],nam[j])==)
{
namss[j]++;
k=;i--;m--;
break;
}
}
if(k==)
{
namss[i]++;
}
}
sort(namss+,namss+m+);
/*for(i=1;i<=n;i++)
printf("%d ",price[i]);
printf("\n");
for(i=1;i<=m;i++)
printf("%d ",namss[i]);
printf("\n");*/
int ans1=,ans2=;
for(i=m;i>=;i--)
{
ans1=ans1+namss[i]*price[m-i+];
ans2=ans2+namss[i]*price[n-m+i];
}
printf("%d %d\n",ans1,ans2);
}
return ;
}

CodeForces 12C Fruits的更多相关文章

  1. cf 12C Fruits(贪心【简单数学】)

    题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b ...

  2. Codeforces Round #252 (Div. 2) B. Valera and Fruits(模拟)

    B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...

  3. codeforces 441B. Valera and Fruits 解题报告

    题目链接:http://codeforces.com/problemset/problem/441/B 题目意思:有 n 棵fruit trees,每课水果树有两个参数描述:水果成熟的时间和这棵树上水 ...

  4. Codeforces 441 B. Valera and Fruits

    B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. Codeforces Round #252 (Div. 2) B. Valera and Fruits

    #include <iostream> #include <vector> #include <algorithm> #include <map> us ...

  6. Codeforces #252 (Div. 2) B. Valera and Fruits

    题目倒是不难,可是读起来非常恶心 依据题目的描写叙述不easy找到适合存储的方法 后来我就想不跟着出题人的思路走 我自己开一个数组c 令c[a[i]] = b[i] 则c[i] == [j] 代表第i ...

  7. Codeforces Round #252 (Div. 2) 441B. Valera and Fruits

    英语不好就是坑啊.这道题把我坑残了啊.5次WA一次被HACK.第二题得分就比第一题高10分啊. 以后一定要加强英语的学习,要不然就跪了. 题意:有一个果园里有非常多树,上面有非常多果实,为了不然成熟的 ...

  8. Codeforces Round 252 (Div. 2)

    layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...

  9. Codeforces Round #468 Div. 2题解

    A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. archlinux锁屏

    启动管理器用的是 slim 发现锁屏可以用 slimlock

  2. windows中的上帝模式开启方法

    在任何地方创建一个新的文件夹 把文件夹命名为"GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}" 回车,ok了

  3. RobotFrameWork接口报文测试-----(二)demo的升级版

    在上一篇,简单的demo实现了讲xml的数据发送服务器端并取得recvi_buf,然后进行了简单的解析的操作.现在就要解决之前提过的2个问题: 1. 步骤这么多,难道每写一个脚本都要重复一次么? 2. ...

  4. 【rails3教材】博客构建过程

    构建rails项目--blog $ rails new blog --skip-bundle $ cd blog $ bundle --local $ bundle install #安装需要的包 $ ...

  5. php 获取mac地址

    <?php  /**   * 获取机器网卡的物理(MAC)地址* 目前支持WIN/LINUX系统   * 编辑: www.jbxue.com**/  class MacAddInfo {     ...

  6. SQl中drop与truncate的区别

    在对SQL的表操作时,我们因不同的需求做出相应的操作. 我来对比一下truncate table '表明'与drop table '表格名'的区别,跟大家一起学习. drop table '表格名'- ...

  7. AMD机制与cMD的区别和概念简要介绍

    1.http://www.cnblogs.com/dojo-lzz/p/4707725.html 2.http://blog.chinaunix.net/uid-26672038-id-4112229 ...

  8. c++实现mlp神经网络

    之前一直用theano训练样本,最近需要转成c或c++实现.在网上参考了一下其它代码,还是喜欢c++.但是看了几份cpp代码之后,发现都多少有些bug,很不爽.由于本人编码能力较弱,还花了不少时间改正 ...

  9. LR 常见问题收集及总结

    一:LoadRunner常见问题整理 1.LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消掉 2.在系统属性-高级-性能-数据执行保护中,添加loadrunner安装目录中的vugen. ...

  10. 执行maven-build.cmd失败

    执行maven-build.cmd失败,显示:"Non-resolvable parent POM: Could not transfer artifact ......",如截图 ...