CodeForces 12C 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
5 3
4 2 1 10 5
apple
orange
mango
7 19
6 5
3 5 1 6 8 1
peach
grapefruit
banana
orange
orange
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的更多相关文章
- cf 12C Fruits(贪心【简单数学】)
题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b ...
- 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 ...
- codeforces 441B. Valera and Fruits 解题报告
题目链接:http://codeforces.com/problemset/problem/441/B 题目意思:有 n 棵fruit trees,每课水果树有两个参数描述:水果成熟的时间和这棵树上水 ...
- Codeforces 441 B. Valera and Fruits
B. Valera and Fruits time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces Round #252 (Div. 2) B. Valera and Fruits
#include <iostream> #include <vector> #include <algorithm> #include <map> us ...
- Codeforces #252 (Div. 2) B. Valera and Fruits
题目倒是不难,可是读起来非常恶心 依据题目的描写叙述不easy找到适合存储的方法 后来我就想不跟着出题人的思路走 我自己开一个数组c 令c[a[i]] = b[i] 则c[i] == [j] 代表第i ...
- Codeforces Round #252 (Div. 2) 441B. Valera and Fruits
英语不好就是坑啊.这道题把我坑残了啊.5次WA一次被HACK.第二题得分就比第一题高10分啊. 以后一定要加强英语的学习,要不然就跪了. 题意:有一个果园里有非常多树,上面有非常多果实,为了不然成熟的 ...
- Codeforces Round 252 (Div. 2)
layout: post title: Codeforces Round 252 (Div. 2) author: "luowentaoaa" catalog: true tags ...
- Codeforces Round #468 Div. 2题解
A. Friends Meeting time limit per test 1 second memory limit per test 256 megabytes input standard i ...
随机推荐
- 组合逻辑的Glitch与时序逻辑的亚稳态
竞争(Race):一个门的输入有两个及以上的变量发生变化时,由于各个输入的组合路径的延时不同,使得在门级输入的状态改变非同时. 冒险或险象(Hazard):竞争的结果,如毛刺Glitch. 相邻信号间 ...
- Android2.2快速入门 zz
http://www.cnblogs.com/over140/archive/2010/09/27/1836567.html 前言 这是前段时间用于公司Android入门培训的资料,学习Android ...
- TortoiseGit文件夹和文件图标不显示解决方法
试了两种方法, 1.修改Max Cached Icons http://www.open-open.com/lib/view/open1414396787325.html 2.修改图标排序 http: ...
- mysql命令行操作
显示数据库 show databases;当前数据库 select database(); 显示表 show tables;更改表名称 alter table 原表名 rename ...
- jeditable参数详解
一.导入js文件 <script type="text/javascript" src="jquery-1.10.2.min.js"></sc ...
- 那些情况该使用它们spin_lock到spin_lock_irqsave【转】
转自:http://blog.csdn.net/wesleyluo/article/details/8807919 权声明:本文为博主原创文章,未经博主允许不得转载. Spinlock的目的是用来同步 ...
- 启动hadoop报192.168.1.151: Address 192.168.1.151 maps to node1, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
使用root用户启动hadoop的时候报错: [root@node1 ~]# su - hadoop -c start-all.sh starting namenode, logging to /ap ...
- ecshop销售排行调用促销价格和市场价格
我们知道在ecshop某些产品销售之后,销售量高的产品销售出去之后,能形成销售排行,ecshop的销售排行必须保持两个条件,首先是ecshop的商品必须库存足够,其次商品该商品必须上架的. 我们分析如 ...
- 【转】如何安装mysql服务
转载地址:http://www.2cto.com/database/201211/168081.html 我刚开始安装mysql的时候,在windows的服务里面可以看到,但是装了以后有一段时间没有 ...
- Discuz! 6.x/7.x 全局变量防御绕过导致命令执行
https://www.secpulse.com/archives/2338.html 模拟register_globals功能的代码,在GPC为off时会调用addslashes()函数处理变量值, ...