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 ...
随机推荐
- qsort函数用法(转)
qsort函数用法 qsort 功 能: 使用快速排序例程进行排序 用 法: void qsort(void *base, int nelem, int width, int (*fcmp)(c ...
- OpenCV cv::Mat类
using namespace cv; 1.Mat的声明: Mat m=Mat(rows, cols, type); Mat m=Mat(Size(width,height), type); type ...
- SQLServer中在视图上使用索引(转载)
在SQL Server中,视图是一个保存的T-SQL查询.视图定义由SQL Server保存,以便它能够用作一个虚拟表来简化查询,并给基表增加另一层安全.但是,它并不占用数据库的任何空间.实际上,在你 ...
- google pinyin elmentary os
sudo apt-get install software-properties-common for ppa. I have been using Sun Pinyin for quite a lo ...
- 我的AutoCAD二次开发之路 (一)
原帖地址 http://379910987.blog.163.com/blog/static/33523797201011184552167/ 今天在改代码的时候,遇到了AddVertexAt方法的用 ...
- 《HTML5高级程序设计》知识点概要(不涉及详细语法)
不断更新. 说明:主要记录html5中的一些注意点或知识点,尽量不涉及具体语法信息. 一.CANVAS: 检测: try{ document.createElement("canvas&qu ...
- 【python cookbook】【字符串与文本】2.在字符串的开头或结尾处做文本匹配
问题:在字符串的开头或结尾处按照指定的文本模式做检查,例如检查文件的扩展名.URL协议类型等: 解决方法:使用str.startswith()和str.endswith()方法 >>> ...
- linux死锁检测的一种思路【转】
转自:http://www.cnblogs.com/mumuxinfei/p/4365697.html 前言: 上一篇博文讲述了pstack的使用和原理. 和jstack一样, pstack能获取进 ...
- Java 门面模式 浅析
Java中的门面模式,一般来说他的用途是隐藏一些不希望用户看到的东西,比如方法,变量,并且这些变量是不能够设置成私有的,因为在系统内部有些地方需要调用.在Tomcat的HttpServletReque ...
- 七牛开发文档php
http://developer.qiniu.com/docs/v6/sdk/php-sdk.html#overview http://developer.qiniu.com/docs/v6/sdk/ ...