codeforces-scrape

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

408B.md (2058B)


      1 Source: https://codeforces.com/problemset/problem/408/B
      2 
      3 B. Garland
      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 Once little Vasya read an article in a magazine on how to make beautiful handmade garland from colored paper. Vasya immediately went to the store and bought *n* colored sheets of paper, the area of each sheet is 1 square meter.
     22 
     23 The garland must consist of exactly *m* pieces of colored paper of arbitrary area, each piece should be of a certain color. To make the garland, Vasya can arbitrarily cut his existing colored sheets into pieces. Vasya is not obliged to use all the sheets to make the garland.
     24 
     25 Vasya wants the garland to be as attractive as possible, so he wants to maximize the total area of ​​*m* pieces of paper in the garland. Calculate what the maximum total area of ​​the pieces of paper in the garland Vasya can get.
     26 
     27 Input
     28 
     29 The first line contains a non-empty sequence of *n* (1 ≤ *n* ≤ 1000) small English letters ("a"..."z"). Each letter means that Vasya has a sheet of paper of the corresponding color.
     30 
     31 The second line contains a non-empty sequence of *m* (1 ≤ *m* ≤ 1000) small English letters that correspond to the colors of the pieces of paper in the garland that Vasya wants to make.
     32 
     33 Output
     34 
     35 Print an integer that is the maximum possible total area of the pieces of paper in the garland Vasya wants to get or -1, if it is impossible to make the garland from the sheets he's got. It is guaranteed that the answer is always an integer.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 aaabbac  
     43 aabbccac
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 6
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 a  
     56 z
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 -1
     63 ```
     64 
     65 Note
     66 
     67 In the first test sample Vasya can make an garland of area 6: he can use both sheets of color *b*, three (but not four) sheets of color *a* and cut a single sheet of color *c* in three, for example, equal pieces. Vasya can use the resulting pieces to make a garland of area 6.
     68 
     69 In the second test sample Vasya cannot make a garland at all — he doesn't have a sheet of color *z*.