codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

12C.md (2064B)


      1 Source: https://codeforces.com/problemset/problem/12/C
      2 
      3 C. Fruits
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 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.
     22 
     23 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).
     24 
     25 Input
     26 
     27 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.
     28 
     29 Output
     30 
     31 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.
     32 
     33 Examples
     34 
     35 Input
     36 
     37 ```
     38 5 3  
     39 4 2 1 10 5  
     40 apple  
     41 orange  
     42 mango
     43 ```
     44 
     45 Output
     46 
     47 ```
     48 7 19
     49 ```
     50 
     51 Input
     52 
     53 ```
     54 6 5  
     55 3 5 1 6 8 1  
     56 peach  
     57 grapefruit  
     58 banana  
     59 orange  
     60 orange
     61 ```
     62 
     63 Output
     64 
     65 ```
     66 11 30
     67 ```