## OCC '19 B2 - Cinematic

View as PDF

Points: 5
Time limit: 2.0s
Java 8 1.4s
Memory limit: 64M

Author:
Problem type

There are movies that can be playing at a movie theater over the year. Each movie has an enjoyment rating of . Each weekend, Momo can choose to watch a movie at the movie theater. There is only movie playing every weekend. After Momo watches a movie, she cannot watch the same movie again even if it plays again. In the planet where Momo lives on, there are weeks in a year. Find the maximum sum of the enjoyment that Momo can obtain from watching the movies.

#### Input Specification

The first line of input contains , the number of movies that can be played, and , the number of weeks in a year.

The next lines of input contain the names of the movies.

The next line of input contains integers, the enjoyment factor of each movie.

The next lines of input contain the name of the movie that is playing that week.

#### Output Specification

Output the maximum sum of enjoyment Momo can get from watching the movies.

#### Constraints

The length of the title of each movie is less than characters long and consists only of alphanumeric characters with no spaces.

#### Sample Input 1

3 5
Doestheblackmoonhowl
Oceaneyes
MobileOrchestra
10 9 8
Doestheblackmoonhowl
MobileOrchestra
Doestheblackmoonhowl
Doestheblackmoonhowl
Doestheblackmoonhowl

#### Sample Output 1

18

#### Explanation 1

Doestheblackmoonhowl and MobileOrchestra are shown during the 5 weeks of the year while Oceaneyes is not. The enjoyment factor of the two movies that are shown during the year is 18.